OWC画图-Microsoft Office Chart Component

1.结构
msdn上只找到office2000的资料,仅供参考。
office.10.gif office.102.gif

 
然后自带的文档一般在 安装盘:\Program Files\Common Files\Microsoft Shared\Web Components\11\2052,里面的OWCVBA11.CHM为OWC的VBA编程参考。

2.编程测试
本例子采用VS.NET2005,C#,Office11实现。

  1 None.gif using  System;
  2 None.gif using  System.Data;
  3 None.gif using  System.Configuration;
  4 None.gif using  System.Web;
  5 None.gif using  System.Web.Security;
  6 None.gif using  System.Web.UI;
  7 None.gif using  System.Web.UI.WebControls;
  8 None.gif using  System.Web.UI.WebControls.WebParts;
  9 None.gif using  System.Web.UI.HtmlControls;
 10 None.gif using  System.ComponentModel;
 11 None.gif
 12 None.gif public  partial  class  _Default : System.Web.UI.Page
 13 ExpandedBlockStart.gifContractedBlock.gif dot.gif {
 14InBlock.gif    protected void Page_Load(object sender, EventArgs e)
 15ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 16InBlock.gif        createPicture("test01.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered3D, "3D 柱状图");
 17InBlock.gif        createPicture("test02.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeSmoothLine, "平滑曲线图");
 18InBlock.gif        createPicture("test03.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeArea, "折线面积图");
 19InBlock.gif        createPicture("test04.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeArea3D, "折线3D面积图");
 20InBlock.gif        createPicture("test05.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeAreaOverlapped3D, "折线3D面积图");
 21InBlock.gif        createPicture("test06.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeAreaStacked, "折线面积图加边框");
 22InBlock.gif        createPicture("test07.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeAreaStacked, "折线面积图加边框");
 23InBlock.gif        createPicture("test08.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeAreaStacked100, "折线面积图加边框百分比图");
 24InBlock.gif        createPicture("test09.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeAreaStacked1003D, "折线3D面积图加边框百分比图");
 25InBlock.gif        createPicture("test11.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeAreaStacked3D, "折线3D面积图加边框");
 26InBlock.gif        createPicture("test12.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBar3D, "横道图3D");
 27InBlock.gif        createPicture("test13.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBarClustered, "横道图");
 28InBlock.gif        createPicture("test14.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBarStacked, "横道图3D");
 29InBlock.gif        createPicture("test15.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBarStacked100, "横道图3D百分比图");
 30InBlock.gif        createPicture("test16.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBarStacked1003D, "横道图3D百分比图");
 31InBlock.gif
 32InBlock.gif        createPicture("test17.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered, "柱状图");
 33InBlock.gif        createPicture("test18.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered3D, "柱状图3D");
 34InBlock.gif        createPicture("test19.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnStacked, "柱状图");
 35InBlock.gif        createPicture("test20.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnStacked100, "柱状图3D百分比图 ");
 36InBlock.gif        createPicture("test21.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnStacked100, "柱状图3D百分比图");
 37InBlock.gif        createPicture("test22.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnStacked, "柱状图");
 38InBlock.gif
 39InBlock.gif        createPicture("test23.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypePie, "饼图"false);
 40InBlock.gif        createPicture("test24.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypePie3D, "饼图"false);
 41InBlock.gif        createPicture("test25.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypePieExploded, "饼图"false);
 42InBlock.gif        createPicture("test26.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypePieExploded3D, "饼图"false);
 43InBlock.gif        createPicture("test27.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypePieStacked, "饼图"false);
 44InBlock.gif         
 45InBlock.gif        //createPicture("test28.gif",Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBubble, "测试统计图"); //测试不通过
 46InBlock.gif        //createPicture("test29.gif",Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBubbleLine, "测试统计图"); //测试不通过  
 47InBlock.gif           
 48ExpandedSubBlockEnd.gif    }

 49InBlock.gif
 50InBlock.gif
 51InBlock.gif    private void createPicture(string fileName, Microsoft.Office.Interop.Owc11.ChartChartTypeEnum type, string title)
 52ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 53InBlock.gif        this.createPicture(fileName,type, title, true);
 54ExpandedSubBlockEnd.gif    }

 55InBlock.gif
 56InBlock.gif    private void createPicture(string fileName,Microsoft.Office.Interop.Owc11.ChartChartTypeEnum type, string title,bool hasAxes)
 57ExpandedSubBlockStart.gifContractedSubBlock.gif    dot.gif{
 58InBlock.gif        string strCategory = "1" + '\t' + "2" + '\t' + "3" + '\t' + "4" + '\t' + "5" + '\t' + "6" + '\t';
 59InBlock.gif        string strValue = "9" + '\t' + "8" + '\t' + "4" + '\t' + "10" + '\t' + "12" + '\t' + "6" + '\t';
 60InBlock.gif
 61InBlock.gif        //图表工作区
 62InBlock.gif        Microsoft.Office.Interop.Owc11.ChartSpace thisChartSpace = new Microsoft.Office.Interop.Owc11.ChartSpace();
 63InBlock.gif        //增加一个图表
 64InBlock.gif        Microsoft.Office.Interop.Owc11.ChChart thisChChart = thisChartSpace.Charts.Add(0);
 65InBlock.gif        //增加一个图表上的系列
 66InBlock.gif        Microsoft.Office.Interop.Owc11.ChSeries thisChSeries = thisChChart.SeriesCollection.Add(0);
 67InBlock.gif
 68InBlock.gif        //显示图例
 69InBlock.gif        thisChChart.HasLegend = true;
 70InBlock.gif
 71InBlock.gif        //设置标题
 72InBlock.gif        thisChChart.HasTitle = true;
 73InBlock.gif        thisChChart.Title.Caption = title;
 74InBlock.gif
 75InBlock.gif        //图表类型
 76InBlock.gif        thisChChart.Type = type;
 77InBlock.gif
 78InBlock.gif        //旋转
 79InBlock.gif        thisChChart.Rotation = 360.00;
 80InBlock.gif        //设置倾斜度
 81InBlock.gif        thisChChart.Inclination = 10.00;
 82InBlock.gif
 83InBlock.gif        if (hasAxes)
 84ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
 85InBlock.gif
 86InBlock.gif            //给定x,y轴图示说明
 87InBlock.gif            thisChChart.Axes[0].HasTitle = true;
 88InBlock.gif            thisChChart.Axes[0].Title.Caption = "月份";
 89InBlock.gif
 90InBlock.gif            thisChChart.Axes[1].HasTitle = true;
 91InBlock.gif            thisChChart.Axes[1].Title.Caption = "数量";
 92ExpandedSubBlockEnd.gif        }

 93InBlock.gif
 94InBlock.gif
 95ExpandedSubBlockStart.gifContractedSubBlock.gif        /**/////底色
 96InBlock.gif        //thisChChart.PlotArea.Floor.Interior.Color = "green";
 97ExpandedSubBlockStart.gifContractedSubBlock.gif        /**/////背景颜色
 98InBlock.gif        //thisChChart.PlotArea.Interior.Color = "red";
 99InBlock.gif
100InBlock.gif        //重叠
101InBlock.gif        //thisChChart.Overlap = 50;
102InBlock.gif
103InBlock.gif        //*********************************************************************
104InBlock.gif        //设置指定图表对象的数据。
105InBlock.gif        //expression.SetData(Dimension, DataSourceIndex, DataReference)
106InBlock.gif        //
107InBlock.gif        //Dimension    ChartDimensionsEnum 常量,必需。指定设置的数据维。
108InBlock.gif        //ChartDimensionsEnum 可以为下列 ChartDimensionsEnum 常量之一。 
109InBlock.gif        //    chDimBubbleValues  设置气泡图上的标志值。 
110InBlock.gif        //    chDimCategories  设置用作分类的值。 
111InBlock.gif        //    chDimCharts  在 HasMultipleCharts 属性设置为 True 时设置新图表的来源字段。 
112InBlock.gif        //    chDimCloseValues  设置股票图的收盘值。 
113InBlock.gif        //    chDimFilter  设置放置于筛选坐标轴的字段。 
114InBlock.gif        //    chDimFormatValues 设置格式映射中的值。 
115InBlock.gif        //    chDimHighValues  设置股票图的盘高值。 
116InBlock.gif        //    chDimLowValues  设置股票图的盘低值。 
117InBlock.gif        //    chDimOpenValues  设置股票图的开盘值。 
118InBlock.gif        //    chDimRValues  设置极坐标图的 R 值。 
119InBlock.gif        //    chDimSeriesNames  设置作为系列名称的值。 
120InBlock.gif        //    chDimThetaValues  设置极坐标图的极角值。 
121InBlock.gif        //    chDimValues 设置绘制图表的值。 
122InBlock.gif        //    chDimXValues  设置 XY 散点图或气泡图的 X 值。 
123InBlock.gif        //    chDimYValues  设置 XY 散点图或气泡图的 Y 值。 
124InBlock.gif        //
125InBlock.gif        //DataSourceIndex    Long 类型,必需。可以为 ChartSpecialDataSourcesEnum 常量。
126InBlock.gif        //    ChartSpecialDataSourcesEnum 可以为下列 ChartSpecialDataSourcesEnum 常量之一。 
127InBlock.gif        //    chDataBound  将指定对象绑定到 DataReference 参数指定的外部数据源。  
128InBlock.gif        //    chDataLinked  将指定对象绑定到其他维。在 Dimension 参数中指定 chDimFormatValues 创建格式映射时使用该值。 
129InBlock.gif        //    chDataLiteral  将指定对象绑定到 DataReference 参数指定的文字类型数据。  
130InBlock.gif        //    chDataNone  清除指定对象。
131InBlock.gif        //
132InBlock.gif        //DataReference      Variant 类型,可选。
133InBlock.gif        //对于 ChChart 和 ChSeries 对象,该参数以 Microsoft Excel 样式的区域引用(例如,“A1:D4”)或行集的列名指定数据引用。
134InBlock.gif        //如果 DataSourceIndex 参数设置为 chDataLiteral,可以将 DataReference 设置为一维数组或逗号分隔列表。
135InBlock.gif        //对于 ChErrorBars 对象,该参数指定可用作误差线数值的 Double 或 String 数组。
136InBlock.gif        //请注意该参数仅适用于自定义误差线(误差线的 Type 属性必须设置为 chErrorBarTypeCustom)。
137InBlock.gif
138InBlock.gif
139InBlock.gif        //设置图标对象中作为系列名称的值
140InBlock.gif        thisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), "日期");
141InBlock.gif        //设置图标对象中用作分类的值
142InBlock.gif        thisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strCategory);
143InBlock.gif        //设置图标对象中用作数据的值
144InBlock.gif        thisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strValue);
145InBlock.gif
146InBlock.gif
147InBlock.gif
148InBlock.gif
149InBlock.gif
150InBlock.gif        //******
151InBlock.gif        //下面为增加图标类型代码,取消注释运行就可以
152InBlock.gif        //******
153InBlock.gif
154InBlock.gif        //增加另外一个图表上的系列
155InBlock.gif        //Microsoft.Office.Interop.Owc11.ChSeries thisChSeries2 = thisChChart.SeriesCollection.Add(0);
156InBlock.gif
157ExpandedSubBlockStart.gifContractedSubBlock.gif        /**/////设置图标对象中作为系列名称的值
158InBlock.gif        //thisChSeries2.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), "曲线日期");
159ExpandedSubBlockStart.gifContractedSubBlock.gif        /**///设置图标对象中用作分类的值
160InBlock.gif        //thisChSeries2.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strCategory);
161ExpandedSubBlockStart.gifContractedSubBlock.gif        /**///设置图标对象中用作数据的值
162InBlock.gif        //thisChSeries2.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strValue);
163InBlock.gif
164ExpandedSubBlockStart.gifContractedSubBlock.gif        /**/////设置第二个图的类型
165InBlock.gif        //thisChSeries2.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeLine;
166InBlock.gif
167ExpandedSubBlockStart.gifContractedSubBlock.gif        /**/////设置刻度
168InBlock.gif        //Microsoft.Office.Interop.Owc11.ChAxis chAxis = thisChChart.Axes.Add(thisChChart.get_Scalings(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues));
169InBlock.gif        //chAxis.Position = Microsoft.Office.Interop.Owc11.ChartAxisPositionEnum.chAxisPositionRight; //刻度在右边
170InBlock.gif
171InBlock.gif
172InBlock.gif        //到处图像文件
173InBlock.gif        try
174ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
175InBlock.gif            thisChartSpace.ExportPicture(Server.MapPath(fileName), "gif"600300);
176InBlock.gif            Response.Write("<img src='" + Server.MapPath(fileName) + "'/>");
177InBlock.gif
178ExpandedSubBlockEnd.gif        }

179InBlock.gif        catch (Exception ex)
180ExpandedSubBlockStart.gifContractedSubBlock.gif        dot.gif{
181InBlock.gif            //抛出异常信息
182InBlock.gif            Response.Write(ex);
183ExpandedSubBlockEnd.gif        }

184ExpandedSubBlockEnd.gif    }

185ExpandedBlockEnd.gif}

186 None.gif



3.测试结果图
单类型图:
test25.gif
test13.gif
test02.gif
test04.gif
test01.gif

多类型图:

test171.gif
test021.gif


4.参考资料
Office Developer Center  http://msdn2.microsoft.com/en-us/library/aa164003(office.10).aspx
如何创建组合图表与图表 Web 组件 http://support.microsoft.com/kb/240263/
2003 .net owc11简单用法! http://blog.csdn.net/pkkfaii/archive/2006/11/14/1384276.aspx
ASP.NET中实时图表的实现   http://blog.csdn.net/yangyifan0/archive/2006/05/17/742416.aspx
microsoft office web 组件(owc11)的编程(.net) http://www.cnblogs.com/mse2002/articles/353731.html
C#编写OWC11组件源代码(2) http://7698.org/c8ccca46-8a4f-4b56-aa38-7f5e254ab6af/



 

转载于:https://www.cnblogs.com/csuwhl/archive/2007/07/22/827227.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值