owc控件是microsoft office 图表控件(owc10为ofiiceXP的组件、owc11为office2003的组件,组件的路径为C:/Program Files/Common Files/Microsoft Shared/Web Components/11/owc11,帮助文件的路径为C:/Program Files/Common Files/Microsoft Shared/Web Components/11/2052),它可以生成三维图、柱状图、饼状图、趋势图和误差图,下面以生成三维图web应用程序为例:
1,添加引用:在“com选项卡”中选择“misrosoft office 11.0 object library”
2,具体代码如下:
1,添加引用:在“com选项卡”中选择“misrosoft office 11.0 object library”
2,具体代码如下:
1
using
System;
2
3
using
System.Collections;
4
5
using
System.ComponentModel;
6
7
using
System.Data;
8
9
using
System.Drawing;
10
11
using
System.Web;
12
13
using
System.Web.UI;
14
15
using
Microsoft.Office.Interop;
16
17
18
namespace
WebApplication2
19
{
20
/**//// <summary>
21
/// WebForm1 的摘要说明。
22
/// </summary>
23
public class WebForm1 : System.Web.UI.Page
24
{
25
26
private void Page_Load(object sender, System.EventArgs e)
27
{
28
string strCategory = "1" + '/t' + "2" + '/t' + "3" + '/t'+"4" + '/t' + "5" + '/t' + "6" + '/t';
29
string strValue = "9" + '/t' + "8" + '/t' + "4" + '/t'+"10" + '/t' + "12" + '/t' + "6" + '/t';
30
31
//声明对象
32
Microsoft.Office.Interop.Owc11.ChartSpace ThisChart = new Microsoft.Office.Interop.Owc11.ChartSpaceClass();
33
Microsoft.Office.Interop.Owc11.ChChart ThisChChart = ThisChart.Charts.Add(0);
34
Microsoft.Office.Interop.Owc11.ChSeries ThisChSeries = ThisChChart.SeriesCollection.Add(0);
35
36
//显示图例
37
ThisChChart.HasLegend = true;
38
//标题
39
ThisChChart.HasTitle = true;
40
ThisChChart.Title.Caption = "统计图";
41
42
//给定x,y轴图示说明
43
ThisChChart.Axes[0].HasTitle = true;
44
ThisChChart.Axes[1].HasTitle = true;
45
ThisChChart.Axes[0].Title.Caption = "月份";
46
ThisChChart.Axes[1].Title.Caption = "数量";
47
48
//图表类型
49
ThisChChart.Type = Microsoft.Office.Interop.Owc11.ChartChartTypeEnum.chChartTypeColumnClustered3D;
50
//旋转
51
ThisChChart.Rotation = 360;
52
ThisChChart.Inclination = 10;
53
//背景颜色
54
ThisChChart.PlotArea.Interior.Color = "red";
55
//底色
56
ThisChChart.PlotArea.Floor.Interior.Color = "green";
57
58
ThisChChart.Overlap = 50;
59
60
/**/////给定series的名字
61
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimSeriesNames,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),"日期");
62
//给定分类
63
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimCategories,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strCategory);
64
//给定值
65
ThisChSeries.SetData(Microsoft.Office.Interop.Owc11.ChartDimensionsEnum.chDimValues,Microsoft.Office.Interop.Owc11.ChartSpecialDataSourcesEnum.chDataLiteral.GetHashCode(),strValue);
66
//导出图像文件
67
try
68
{
69
70
ThisChart.ExportPicture(Server.MapPath("chart.gif"),"gif",600,350);
71
Response.Write( "<IMG SRC='" + Server.MapPath("chart.gif") + "'/>");
72
}
73
catch(Exception ee)
74
{
75
76
}
77
78
// object [] objarr=new object[3];
79
// objarr[0]=12;
80
// objarr[1]=13;
81
// objarr[2]=14;
82
// DataTable dt=new DataTable();
83
// dt.Columns.Add("id");
84
// dt.Columns.Add("wei");
85
// dt.Columns.Add("hei");
86
// dt.Rows.Add(objarr);
87
// DataSet ds=new DataSet();
88
// ds.Tables.Add(dt);
89
// Response.Write(this.toChartLine3(ds,"100","","adasd","sdasad","sadsadsa"));
90
}
91
92
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
93
override protected void OnInit(EventArgs e)
94
{
95
//
96
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
97
//
98
InitializeComponent();
99
base.OnInit(e);
100
}
101
102
/**//// <summary>
103
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
104
/// 此方法的内容。
105
/// </summary>
106
private void InitializeComponent()
107
{
108
this.Load += new System.EventHandler(this.Page_Load);
109
110
}
111
#endregion
112
113
}
114
}

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

帮助OWCDCH11.CHM
系统驱动器:/Program Files/Common Files/Microsoft Shared/Web Components/11/2052/OWCDCH11.CHM(但是必须安装office 2003)