msdn上只找到office2000的資料,僅供參考。
然後自帶的文檔一般在 安裝盤:/Program Files/Common Files/Microsoft Shared/Web Components/11/2052,裏面的OWCVBA11.CHM爲OWC的VBA編程參考。
2.編程測試
本例子採用VS.NET2005,C#,Office11實現。
1
using System;
2
using System.Data;
3
using System.Configuration;
4
using System.Web;
5
using System.Web.Security;
6
using System.Web.UI;
7
using System.Web.UI.WebControls;
8
using System.Web.UI.WebControls.WebParts;
9
using System.Web.UI.HtmlControls;
10
using System.ComponentModel;
11![None.gif]()
12
public partial class _Default : System.Web.UI.Page
13
{
14
protected void Page_Load(object sender, EventArgs e)
15
{
16
createPicture("test01.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered3D, "3D 柱狀圖");
17
createPicture("test02.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeSmoothLine, "平滑曲線圖");
18
createPicture("test03.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeArea, "折線面積圖");
19
createPicture("test04.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeArea3D, "折線3D面積圖");
20
createPicture("test05.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeAreaOverlapped3D, "折線3D面積圖");
21
createPicture("test06.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeAreaStacked, "折線面積圖加邊框");
22
createPicture("test07.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeAreaStacked, "折線面積圖加邊框");
23
createPicture("test08.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeAreaStacked100, "折線面積圖加邊框百分比圖");
24
createPicture("test09.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeAreaStacked1003D, "折線3D面積圖加邊框百分比圖");
25
createPicture("test11.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeAreaStacked3D, "折線3D面積圖加邊框");
26
createPicture("test12.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBar3D, "橫道圖3D");
27
createPicture("test13.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBarClustered, "橫道圖");
28
createPicture("test14.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBarStacked, "橫道圖3D");
29
createPicture("test15.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBarStacked100, "橫道圖3D百分比圖");
30
createPicture("test16.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBarStacked1003D, "橫道圖3D百分比圖");
31![InBlock.gif]()
32
createPicture("test17.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered, "柱狀圖");
33
createPicture("test18.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered3D, "柱狀圖3D");
34
createPicture("test19.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnStacked, "柱狀圖");
35
createPicture("test20.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnStacked100, "柱狀圖3D百分比圖 ");
36
createPicture("test21.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnStacked100, "柱狀圖3D百分比圖");
37
createPicture("test22.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnStacked, "柱狀圖");
38![InBlock.gif]()
39
createPicture("test23.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypePie, "餅圖", false);
40
createPicture("test24.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypePie3D, "餅圖", false);
41
createPicture("test25.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypePieExploded, "餅圖", false);
42
createPicture("test26.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypePieExploded3D, "餅圖", false);
43
createPicture("test27.gif", Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypePieStacked, "餅圖", false);
44
45
//createPicture("test28.gif",Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBubble, "測試統計圖"); //測試不通過
46
//createPicture("test29.gif",Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeBubbleLine, "測試統計圖"); //測試不通過
47
48
}
49![InBlock.gif]()
50![InBlock.gif]()
51
private void createPicture(string fileName, Microsoft.Office.Interop.Owc11.ChartChartTypeEnum type, string title)
52
{
53
this.createPicture(fileName,type, title, true);
54
}
55![InBlock.gif]()
56
private void createPicture(string fileName,Microsoft.Office.Interop.Owc11.ChartChartTypeEnum type, string title,bool hasAxes)
57
{
58
string strCategory = "1" + '/t' + "2" + '/t' + "3" + '/t' + "4" + '/t' + "5" + '/t' + "6" + '/t';
59
string strValue = "9" + '/t' + "8" + '/t' + "4" + '/t' + "10" + '/t' + "12" + '/t' + "6" + '/t';
60![InBlock.gif]()
61
//圖表工作區
62
Microsoft.Office.Interop.Owc11.ChartSpace thisChartSpace = new Microsoft.Office.Interop.Owc11.ChartSpace();
63
//增加一個圖表
64
Microsoft.Office.Interop.Owc11.ChChart thisChChart = thisChartSpace.Charts.Add(0);
65
//增加一個圖表上的系列
66
Microsoft.Office.Interop.Owc11.ChSeries thisChSeries = thisChChart.SeriesCollection.Add(0);
67![InBlock.gif]()
68
//顯示圖例
69
thisChChart.HasLegend = true;
70![InBlock.gif]()
71
//設置標題
72
thisChChart.HasTitle = true;
73
thisChChart.Title.Caption = title;
74![InBlock.gif]()
75
//圖表類型
76
thisChChart.Type = type;
77![InBlock.gif]()
78
//旋轉
79
thisChChart.Rotation = 360.00;
80
//設置傾斜度
81
thisChChart.Inclination = 10.00;
82![InBlock.gif]()
83
if (hasAxes)
84
{
85![InBlock.gif]()
86
//給定x,y軸圖示說明
87
thisChChart.Axes[0].HasTitle = true;
88
thisChChart.Axes[0].Title.Caption = "月份";
89![InBlock.gif]()
90
thisChChart.Axes[1].HasTitle = true;
91
thisChChart.Axes[1].Title.Caption = "數量";
92
}
93![InBlock.gif]()
94![InBlock.gif]()
95
////底色
96
//thisChChart.PlotArea.Floor.Interior.Color = "green";
97
////背景顏色
98
//thisChChart.PlotArea.Interior.Color = "red";
99![InBlock.gif]()
100
//重疊
101
//thisChChart.Overlap = 50;
102![InBlock.gif]()
103
//*********************************************************************
104
//設置指定圖表對象的數據。
105
//expression.SetData(Dimension, DataSourceIndex, DataReference)
106
//
107
//Dimension ChartDimensionsEnum 常量,必需。指定設置的數據維。
108
//ChartDimensionsEnum 可以爲下列 ChartDimensionsEnum 常量之一。
109
// chDimBubbleValues 設置氣泡圖上的標誌值。
110
// chDimCategories 設置用作分類的值。
111
// chDimCharts 在 HasMultipleCharts 屬性設置爲 True 時設置新圖表的來源字段。
112
// chDimCloseValues 設置股票圖的收盤值。
113
// chDimFilter 設置放置於篩選座標軸的字段。
114
// chDimFormatValues 設置格式映射中的值。
115
// chDimHighValues 設置股票圖的盤高值。
116
// chDimLowValues 設置股票圖的盤低值。
117
// chDimOpenValues 設置股票圖的開盤值。
118
// chDimRValues 設置極座標圖的 R 值。
119
// chDimSeriesNames 設置作爲系列名稱的值。
120
// chDimThetaValues 設置極座標圖的極角值。
121
// chDimValues 設置繪製圖表的值。
122
// chDimXValues 設置 XY 散點圖或氣泡圖的 X 值。
123
// chDimYValues 設置 XY 散點圖或氣泡圖的 Y 值。
124
//
125
//DataSourceIndex Long 類型,必需。可以爲 ChartSpecialDataSourcesEnum 常量。
126
// ChartSpecialDataSourcesEnum 可以爲下列 ChartSpecialDataSourcesEnum 常量之一。
127
// chDataBound 將指定對象綁定到 DataReference 參數指定的外部數據源。
128
// chDataLinked 將指定對象綁定到其他維。在 Dimension 參數中指定 chDimFormatValues 創建格式映射時使用該值。
129
// chDataLiteral 將指定對象綁定到 DataReference 參數指定的文字類型數據。
130
// chDataNone 清除指定對象。
131
//
132
//DataReference Variant 類型,可選。
133
//對於 ChChart 和 ChSeries 對象,該參數以 Microsoft Excel 樣式的區域引用(例如,“A1:D4”)或行集的列名指定數據引用。
134
//如果 DataSourceIndex 參數設置爲 chDataLiteral,可以將 DataReference 設置爲一維數組或逗號分隔列表。
135
//對於 ChErrorBars 對象,該參數指定可用作誤差線數值的 Double 或 String 數組。
136
//請注意該參數僅適用於自定義誤差線(誤差線的 Type 屬性必須設置爲 chErrorBarTypeCustom)。
137![InBlock.gif]()
138![InBlock.gif]()
139
//設置圖標對象中作爲系列名稱的值
140
thisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), "日期");
141
//設置圖標對象中用作分類的值
142
thisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strCategory);
143
//設置圖標對象中用作數據的值
144
thisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strValue);
145![InBlock.gif]()
146![InBlock.gif]()
147![InBlock.gif]()
148![InBlock.gif]()
149![InBlock.gif]()
150
//******
151
//下面爲增加圖標類型代碼,取消註釋運行就可以
152
//******
153![InBlock.gif]()
154
//增加另外一個圖表上的系列
155
//Microsoft.Office.Interop.Owc11.ChSeries thisChSeries2 = thisChChart.SeriesCollection.Add(0);
156![InBlock.gif]()
157
////設置圖標對象中作爲系列名稱的值
158
//thisChSeries2.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), "曲線日期");
159
//////設置圖標對象中用作分類的值
160
//thisChSeries2.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strCategory);
161
//////設置圖標對象中用作數據的值
162
//thisChSeries2.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues, Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(), strValue);
163![InBlock.gif]()
164
////設置第二個圖的類型
165
//thisChSeries2.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeLine;
166![InBlock.gif]()
167
////設置刻度
168
//Microsoft.Office.Interop.Owc11.ChAxis chAxis = thisChChart.Axes.Add(thisChChart.get_Scalings(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues));
169
//chAxis.Position = Microsoft.Office.Interop.Owc11.ChartAxisPositionEnum.chAxisPositionRight; //刻度在右邊
170![InBlock.gif]()
171![InBlock.gif]()
172
//到處圖像文件
173
try
174
{
175
thisChartSpace.ExportPicture(Server.MapPath(fileName), "gif", 600, 300);
176
Response.Write("<img src='" + Server.MapPath(fileName) + "'/>");
177![InBlock.gif]()
178
}
179
catch (Exception ex)
180
{
181
//拋出異常信息
182
Response.Write(ex);
183
}
184
}
185
}
186![None.gif]()
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
3.測試結果圖
單類型圖:
多類型圖:
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/