资源描述
.NET使用DotNetCharting控件生成报表记录图总结
在做项目时要对数据进行记录分析,所以必须生成一些报表记录图(如柱形图、饼图、曲线图等),网上强烈推荐了使用DotNetCharting控件来实现,于是自己对DotNetCharting控件进行了简朴的学习,下面先简朴介绍一下DotNetCharting控件及其使用。
DotNetCharting是一个非常棒的.NET图表控件,对中文支持非常好,并且操作方便,开发快速,既有for webform 也有for winform的,并且.net1.1和2.0都有支持。它的官方地址是
本站也提供了DotNetCharting破解版本下载: 附件: dotnetCHARTING.rar (下载 36 次)
强烈推荐一下DotNetCharting的demo地址:
这个是所有的 DEMO 演示
这个是 Online Documentation 里面会有具体的说明和用法。
DotNetCharting的简朴使用方法:
1.把\bin\dotnetCHARTING.dll添加到工具箱,并且添加引用;
2.把控件拖到你的网页上,然后添加引用using dotnetCHARTING;就可以用了;
3.接下来是自己写的对DotNetCharting操作的封装类,以便于在程序里调用。
ShowData.cs
1. using System;
2. using System.Data;
3. using System.Text;
4. using dotnetCHARTING;
5.
6. namespace FLX.ComplexQuery
7. {
8. /**//// <summary>
9. /// 彭建军
10. /// 根据数据动态生成图形(柱形图、饼图、曲线图)
11. /// 2023-06-19
12. /// </summary>
13. public class ShowData
14. {
15.
16. 属性#region 属性
17. private string _phaysicalimagepath;//图片存放途径
18. private string _title; //图片标题
19. private string _xtitle;//图片x座标名称
20. private string _ytitle;//图片y座标名称
21. private string _seriesname;//图例名称
22. private int _picwidth;//图片宽度
23. private int _pichight;//图片高度
24. private DataTable _dt;//图片数据源
25.
26. /**//// <summary>
27. /// 图片存放途径
28. /// </summary>
29. public string PhaysicalImagePath
30. {
31. set{_phaysicalimagepath=value;}
32. get{return _phaysicalimagepath;}
33. }
34. /**//// <summary>
35. /// 图片标题
36. /// </summary>
37. public string Title
38. {
39. set{_title=value;}
40. get{return _title;}
41. }
42. /**//// <summary>
43. /// 图片标题
44. /// </summary>
45. public string XTitle
46. {
47. set{_xtitle=value;}
48. get{return _xtitle;}
49. }
50. /**//// <summary>
51. /// 图片标题
52. /// </summary>
53. public string YTitle
54. {
55. set{_ytitle=value;}
56. get{return _ytitle;}
57. }
58.
59. /**//// <summary>
60. /// 图例名称
61. /// </summary>
62. public string SeriesName
63. {
64. set{_seriesname=value;}
65. get{return _seriesname;}
66. }
67. /**//// <summary>
68. /// 图片宽度
69. /// </summary>
70. public int PicWidth
71. {
72. set{_picwidth=value;}
73. get{return _picwidth;}
74. }
75. /**//// <summary>
76. /// 图片高度
77. /// </summary>
78. public int PicHight
79. {
80. set{_pichight=value;}
81. get{return _pichight;}
82. }
83. /**//// <summary>
84. /// 图片数据源
85. /// </summary>
86. public DataTable DataSource
87. {
88. set{_dt=value; }
89. get{return _dt;}
90. }
91. #endregion
92.
93. 构造函数#region 构造函数
94. public ShowData()
95. {
96. //
97. // TODO: 在此处添加构造函数逻辑
98. //
99. }
100.
101. public ShowData(string PhaysicalImagePath,string Title,string XTitle,string YTitle,string SeriesName)
102. {
103. _phaysicalimagepath=PhaysicalImagePath;
104. _title=Title;
105. _xtitle=XTitle;
106. _ytitle=YTitle;
107. _seriesname=SeriesName;
108. }
109. #endregion
110.
111. 输出柱形图#region 输出柱形图
112. /**//// <summary>
113. /// 柱形图
114. /// </summary>
115. /// <returns></returns>
116. public void CreateColumn(dotnetCHARTING.Chart chart)
117. {
118. chart.Title=this._title;
119. chart.XAxis.Label.Text=this._xtitle;
120. chart.YAxis.Label.Text=this._ytitle;
121. chart.TempDirectory =this._phaysicalimagepath;
122. chart.Width = this._picwidth;
123. chart.Height = this._pichight;
124. chart.Type = ChartType.Combo ;
125. chart.Series.Type =SeriesType.Cylinder;
126. chart.Series.Name = this._seriesname;
127. chart.Series.Data = this._dt;
128. chart.SeriesCollection.Add();
129. chart.DefaultSeries.DefaultElement.ShowValue = true;
130. chart.ShadingEffect = true;
131. chart.Use3D = false;
132. chart.Series.DefaultElement.ShowValue =true;
133. }
134. #endregion
135.
136. 输出饼图#region 输出饼图
137. /**//// <summary>
138. /// 饼图
139. /// </summary>
140. /// <returns></returns>
141. public void CreatePie(dotnetCHARTING.Chart chart)
142. {
143. chart.Title=this._title;
144. chart.TempDirectory =this._phaysicalimagepath;
145. chart.Width = this._picwidth;
146. chart.Height = this._pichight;
147. chart.Type = ChartType.Pie;
148. chart.Series.Type =SeriesType.Cylinder;
149. chart.Series.Name = this._seriesname;
150.
151. chart.ShadingEffect = true;
152. chart.Use3D = false;
153. chart.DefaultSeries.DefaultElement.Transparency = 20;
154. chart.DefaultSeries.DefaultElement.ShowValue = true;
155. chart.PieLabelMode = PieLabelMode.Outside;
156. chart.SeriesCollection.Add(getArrayData());
157. chart.Series.DefaultElement.ShowValue = true;
158. }
159.
160. private SeriesCollection getArrayData()
161. {
162. SeriesCollection SC = new SeriesCollection();
163. DataTable dt = this._dt;
164.
165. for(int i=0; i < dt.Rows.Count; i++)
166. {
167. Series s = new Series();
168. s.Name = dt.Rows[0].ToString();
169.
170. Element e = new Element();
171.
172. // 每元素的名称
173. e.Name = dt.Rows[0].ToString();
174.
175. // 每元素的大小数值
176. e.YValue=Convert.ToInt32(dt.Rows[1].ToString());
177.
178. s.Elements.Add(e);
179. SC.Add(s);
180. }
181. return SC;
182. }
183. #endregion
184.
185. 输出曲线图#region 输出曲线图
186. /**//// <summary>
187. /// 曲线图
188. /// </summary>
189. /// <returns></returns>
190. public void CreateLine(dotnetCHARTING.Chart chart)
191. {
192. chart.Title=this._title;
193. chart.XAxis.Label.Text=this._xtitle;
194. chart.YAxis.Label.Text=this._ytitle;
195. chart.TempDirectory =this._phaysicalimagepath;
196. chart.Width = this._picwidth;
197. chart.Height = this._pichight;
198. chart.Type = ChartType.Combo ;
199. chart.Series.Type =SeriesType.Line;
200. chart.Series.Name = this._seriesname;
201. chart.Series.Data = this._dt;
202. chart.SeriesCollection.Add();
203. chart.DefaultSeries.DefaultElement.ShowValue = true;
204. chart.ShadingEffect = true;
205. chart.Use3D = false;
206. chart.Series.DefaultElement.ShowValue =true;
207. }
208. #endregion
209.
210. 调用说明及范例#region 调用说明及范例
211. // 在要显示记录图的页面代码直接调用,方法类似如下:
212. //
213. // ShowData show=new ShowData();
214. // show.Title ="2023年各月消费情况记录";
215. // show.XTitle ="月份";
216. // show.YTitle ="金额(万元)";
217. // show.PicHight =300;
218. // show.PicWidth =600;
219. // show.SeriesName ="具体详情";
220. // show.PhaysicalImagePath ="ChartImages";
221. // show.DataSource =this.GetDataSource();
222. // show.CreateColumn(this.Chart1);
223. #endregion
224.
225. }
226. }
复制代码
效果图展示:
1、饼图
2、柱形图
3、曲线图
补充:
帖子发了一天,没人回答我多维记录图的实现方式,只好自己去dotnetcharting的官方网站下载了最新的dotnetcharting控件,在 dotnetcharting控件的使用说明文档中具体地介绍了各种多维记录图的实现方式。现把说明文档贴出来供大家下载
dotnetcharting使用说明文档:附件: dotnetcharting使用说明.rar (下载 38 次)
追加补充新内容:
1、解决“每运营一次DotNetCharting页面,就会生成一个图片,这样图片不是越来越多吗?请问如何自动删除DotNetCharting生成的图片呢”的问题,参照 ASP.NET删除文献夹里的所有文献 。
2、解决“(1)生成的图片带超链接导向官网,如何解决呀?(2)我使用这个控件后,图形可以显示出来。但是发现一个小问题。就是在图形的左上方和图形的下面都隐含了超链接,鼠标移动到这两个区域后,点击都会链接到。很奇怪,这是和破解有管吗?”等类似的问题,参照 DotnetCharting控件的破解方法 。
展开阅读全文