C#调用office2003的OWC11组件生成报表统计图

owc11控件是microsoft office图表控件(owc10为ofiiceXP的组件、owc11为office2003的组件,组件的路径为C:/ProgramFiles/Common Files/Microsoft Shared/WebComponents/11/owc11,帮助文件的路径为C:/Program Files/Common Files/MicrosoftShared/Web Components/11/2052),调用它可以生成三维图、柱状图、饼状图、趋势图和误差图等。 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
    首先必须添加引用owc11:在“com选项卡”中选择“misrosoft office 11.0 objectlibrary”或直接选择路径为C:/Program Files/Common Files/Microsoft Shared/WebComponents/11/owc11的owc11; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
    接下来是自己写的对owc11操作的封装类,以便于在程序里调用。 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
具体代码及说明如下: ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
using System; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
using System.Data; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
using System.Text; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
using Microsoft.Office.Interop.Owc11; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
namespace Chat ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
{ ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
    ///    ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
    /// 星辰.Net技术社区 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
    /// [url]http://www.netcsharp.cn[/url] ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
    /// 2008-07-11 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
    /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
    public class ShowChart ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
    { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        #region 属性 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        private string _phaysicalimagepath;//图片存放路径 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        private string _title; //图片标题 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        private string _xtitle;//图片x座标名称 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        private string _ytitle;//图片y座标名称 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        private string _seriesname;//图例名称 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        private int _picwidth;//图片宽度 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        private int _pichight;//图片高度 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        private DataTable _datasource;//图片数据源 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        private string strCategory;//图片数据源的分类 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        private string strValue;//图片数据源的值 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// 图片存放路径 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        public string PhaysicalImagePath ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            set { _phaysicalimagepath = value; } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            get { return _phaysicalimagepath; } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// 图片标题 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        public string Title ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            set { _title = value; } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            get { return _title; } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// 图片标题 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        public string XTitle ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            set { _xtitle = value; } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            get { return _xtitle; } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// 图片标题 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        public string YTitle ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            set { _ytitle = value; } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            get { return _ytitle; } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// 图例名称 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        public string SeriesName ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            set { _seriesname = value; } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            get { return _seriesname; } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// 图片宽度 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        public int PicWidth ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            set { _picwidth = value; } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            get { return _picwidth; } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// 图片高度 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        public int PicHight ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            set { _pichight = value; } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            get { return _pichight; } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// 图片数据源 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        public DataTable DataSource ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            set ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
                _datasource = value; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
                strCategory = GetColumnsStr(_datasource); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
                strValue = GetValueStr(_datasource); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            get { return _datasource; } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// 图片数据源的分类 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        private string GetColumnsStr(DataTable dt) ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            StringBuilder strList = new StringBuilder(); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            foreach (DataRow r in dt.Rows) ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
                strList.Append(r[0].ToString() + '/t'); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            return strList.ToString(); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// 图片数据源的值 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        private string GetValueStr(DataTable dt) ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            StringBuilder strList = new StringBuilder(); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            foreach (DataRow r in dt.Rows) ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
                strList.Append(r[1].ToString() + '/t'); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            return strList.ToString(); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        #endregion ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        #region 构造函数 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        public ShowChart() ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            // ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            // TODO: 在此处添加构造函数逻辑 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            // ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        public ShowChart(string PhaysicalImagePath, string Title, string XTitle, string YTitle, string SeriesName) ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            _phaysicalimagepath = PhaysicalImagePath; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            _title = Title; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            _xtitle = XTitle; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            _ytitle = YTitle; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            _seriesname = SeriesName; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        #endregion ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        #region 输出柱形图 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// 柱形图 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        public string CreateColumn() ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            Microsoft.Office.Interop.Owc11.ChartSpace objCSpace = new Microsoft.Office.Interop.Owc11.ChartSpaceClass();//创建ChartSpace对象来放置图表  ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            Microsoft.Office.Interop.Owc11.ChChart objChart = objCSpace.Charts.Add(0);//在ChartSpace对象中添加图表,Add方法返回chart对象 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //指定图表的类型。类型由OWC.ChartChartTypeEnum枚举值得到//Microsoft.Office.Interop.OWC.ChartChartTypeEnum ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //指定图表是否需要图例 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.HasLegend = true; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //标题 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.HasTitle = true; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.Title.Caption = _title; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //  objChart.Title.Font.Bold=true; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //  objChart.Title.Font.Color="blue"; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            #region 样式设置 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //旋转 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //  objChart.Rotation  = 360;//表示指定三维图表的旋转角度 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //  objChart.Inclination = 10;//表示指定三维图表的视图斜率。有效范围为 -90 到 90 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //背景颜色 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //  objChart.PlotArea.Interior.Color = "red"; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //底座颜色 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //  objChart.PlotArea.Floor.Interior.Color = "green"; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            // ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //  objChart.Overlap = 50;//单个类别中标志之间的重叠量 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            #endregion ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //x,y轴的图示说明 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.Axes[0].HasTitle = true; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.Axes[0].Title.Caption = "X : " + this._xtitle; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.Axes[1].HasTitle = true; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.Axes[1].Title.Caption = "Y : " + this._ytitle; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //添加一个series ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            Microsoft.Office.Interop.Owc11.ChSeries ThisChSeries = objChart.SeriesCollection.Add(0); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //给定series的名字 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames, ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
                Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), SeriesName); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //给定分类 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories, ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
                Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strCategory); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //给定值 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues, ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
                Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strValue); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //表示柱形图上的单个数据标志 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            Microsoft.Office.Interop.Owc11.ChDataLabels dl = objChart.SeriesCollection[0].DataLabelsCollection.Add(); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            dl.HasValue = true; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //  dl.Position=Microsoft.Office.Interop.Owc11.ChartDataLabelPositionEnum.chLabelPositionOutsideEnd; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            string filename = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".gif"; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            string strAbsolutePath = _phaysicalimagepath + "//" + filename; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objCSpace.ExportPicture(strAbsolutePath, "GIF", _picwidth, _pichight);//输出成GIF文件. ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            return filename; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        #endregion ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        #region 输出饼图 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// 饼图 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        public string CreatePie() ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            Microsoft.Office.Interop.Owc11.ChartSpace objCSpace = new Microsoft.Office.Interop.Owc11.ChartSpaceClass();//创建ChartSpace对象来放置图表  ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            Microsoft.Office.Interop.Owc11.ChChart objChart = objCSpace.Charts.Add(0);//在ChartSpace对象中添加图表,Add方法返回chart对象 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //指定图表的类型 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypePie; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //指定图表是否需要图例 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.HasLegend = true; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //标题 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.HasTitle = true; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.Title.Caption = _title; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //添加一个series ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            Microsoft.Office.Interop.Owc11.ChSeries ThisChSeries = objChart.SeriesCollection.Add(0); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //给定series的名字 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames, ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
                Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), SeriesName); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //给定分类 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories, ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
                Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strCategory); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //给定值 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues, ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
                Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strValue); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //表示系列或趋势线上的单个数据标志 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            Microsoft.Office.Interop.Owc11.ChDataLabels dl = objChart.SeriesCollection[0].DataLabelsCollection.Add(); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            dl.HasValue = true; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            dl.HasPercentage = true; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //图表绘图区的图例放置在右侧。 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //  dl.Position=Microsoft.Office.Interop.Owc11.ChartDataLabelPositionEnum.chLabelPositionRight; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            string filename = DateTime.Now.Ticks.ToString() + ".gif"; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            string strAbsolutePath = _phaysicalimagepath + "//" + filename; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objCSpace.ExportPicture(strAbsolutePath, "GIF", _picwidth, _pichight);//输出成GIF文件. ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            return filename; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        #endregion ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        #region 输出曲线图 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// 曲线图 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        /// ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        public string CreateLine() ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        { ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //创建ChartSpace对象来放置图表 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            Microsoft.Office.Interop.Owc11.ChartSpace objCSpace = new Microsoft.Office.Interop.Owc11.ChartSpaceClass(); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //在ChartSpace对象中添加图表,Add方法返回chart对象 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            Microsoft.Office.Interop.Owc11.ChChart objChart = objCSpace.Charts.Add(0); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeSmoothLine; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //指定图表是否需要图例 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.HasLegend = true; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //给定标题 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.HasTitle = true; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.Title.Caption = this._title; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //给定x,y轴的图示说明 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.Axes[0].HasTitle = true; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.Axes[0].Title.Caption = "X : " + this._xtitle; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.Axes[1].HasTitle = true; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.Axes[1].Title.Caption = "Y : " + this._ytitle; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //添加一个series ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.SeriesCollection.Add(0); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //给定series的名字 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.SeriesCollection[0].SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames, ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
                +(int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, SeriesName); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //给定分类 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.SeriesCollection[0].SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories, ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
                +(int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, strCategory); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //给定值 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objChart.SeriesCollection[0].SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues, (int)Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral, strValue); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            //表示曲线上的单个数据标志 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            Microsoft.Office.Interop.Owc11.ChDataLabels dl = objChart.SeriesCollection[0].DataLabelsCollection.Add(); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            dl.HasValue = true; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            string filename = DateTime.Now.ToString("yyyyMMddHHmmssff") + ".gif"; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            string strAbsolutePath = _phaysicalimagepath + "//" + filename; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            objCSpace.ExportPicture(strAbsolutePath, "GIF", _picwidth, _pichight);//输出成GIF文件. ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
            return filename; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        #endregion ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        #region 调用说明及范例 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        //        在要显示统计图的页面代码直接调用,方法类似如下: ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        // ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        //        ShowChart chart=new ShowChart();  创建对象 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        //        chart.Title="标题"; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        //        chart.XTitle ="月份"; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        //        chart.YTitle ="数量"; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        //        chart.SeriesName="图例"; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        //        string filepath=Server.MapPath(".")+"//ChartImages"; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        //        chart.PhaysicalImagePath=filepath; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        //        chart.PicHight=320; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        //        chart.PicWidth=500; ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        //        chart.DataSource=GetData();//这是你的数据源 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        //        Response.Write(""); ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        //        this.Image1.ImageUrl=filepath+"//"+chart.CreateBar();//显示给图像控件。 ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
        #endregion ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
    } ^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
}
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
效果图展示:^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
    1.柱形图^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
    2.饼图^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
    3.曲线图^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
^xæ_‰7ÏñAwww.netcsharp.cn nQƒ9ù¤X=î
Retrieving the COM class factory for component with CLSID {0002E55D-0000-0000-C000-000000000046} failed due to the following error: 80040154. 收藏 Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {0002E55D-0000-0000-C000-000000000046} failed due to the following error: 80040154. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [COMException (0x80040154): Retrieving the COM class factory for component with CLSID {0002E55D-0000-0000-C000-000000000046} failed due to the following error: 80040154.] GraphPage.Page_Load(Object sender, EventArgs e) +1097 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627 -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082 请大家帮忙 谢谢 Server Error in '/' Application. -------------------------------------------------------------------------------- Retrieving the COM class factory for component with CLSID {0002E55D-0000-0000-C000-000000000046} failed due to the following error: 80040154.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值