OWC畫圖-Microsoft Office Chart Component

1.結構
msdn上只找到office2000的資料,僅供參考。
office.10.gifoffice.102.gif

 
然後自帶的文檔一般在 安裝盤:/Program Files/Common Files/Microsoft Shared/Web Components/11/2052,裏面的OWCVBA11.CHM爲OWC的VBA編程參考。

2.編程測試
本例子採用VS.NET2005,C#,Office11實現。

  1None.gifusing System;
  2None.gifusing System.Data;
  3None.gifusing System.Configuration;
  4None.gifusing System.Web;
  5None.gifusing System.Web.Security;
  6None.gifusing System.Web.UI;
  7None.gifusing System.Web.UI.WebControls;
  8None.gifusing System.Web.UI.WebControls.WebParts;
  9None.gifusing System.Web.UI.HtmlControls;
 10None.gifusing System.ComponentModel;
 11None.gif
 12None.gifpublic partial class _Default : System.Web.UI.Page
 13ExpandedBlockStart.gif{
 14InBlock.gif    protected void Page_Load(object sender, EventArgs e)
 15ExpandedSubBlockStart.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.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.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.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.gif        ////底色
 96InBlock.gif        //thisChChart.PlotArea.Floor.Interior.Color = "green";
 97ExpandedSubBlockStart.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.gif        ////設置圖標對象中作爲系列名稱的值
158InBlock.gif        //thisChSeries2.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), "曲線日期");
159ExpandedSubBlockStart.gif        //////設置圖標對象中用作分類的值
160InBlock.gif        //thisChSeries2.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strCategory);
161ExpandedSubBlockStart.gif        //////設置圖標對象中用作數據的值
162InBlock.gif        //thisChSeries2.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strValue);
163InBlock.gif
164ExpandedSubBlockStart.gif        ////設置第二個圖的類型
165InBlock.gif        //thisChSeries2.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeLine;
166InBlock.gif
167ExpandedSubBlockStart.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.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.gif        {
181InBlock.gif            //拋出異常信息
182InBlock.gif            Response.Write(ex);
183ExpandedSubBlockEnd.gif        }

184ExpandedSubBlockEnd.gif    }

185ExpandedBlockEnd.gif}

186None.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/
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章