在做項目時要對數據進行統計分析,所以必須生成一些報表統計圖(如柱形圖、餅圖、曲線圖等),網上強烈推薦了使用DotNetCharting控件來實現,於是自己對DotNetCharting控件進行了簡單的學習,下面先簡單介紹一下DotNetCharting控件及其使用。
DotNetCharting是一個非常棒的.NET圖表控件,對中文支持非常好,而且操作方便,開發快速,既有for webform 也有for winform的,而且.net1.1和2.0都有支持。它的官方地址是http://www.dotnetcharting.com/
本站也提供了DotNetCharting破解版本下載: http://files.cnblogs.com/dreamof/dotnetcharting.rar
強烈推薦一下DotNetCharting的demo地址:
這個是所有的 DEMO 演示 http://www.dotnetcharting.com/demo.aspx
這個是 Online Documentation http://www.dotnetcharting.com/documentation/v4_4/webframe.html 裏面會有詳細的說明和用法。
DotNetCharting的簡單使用方法:
1.把/bin/dotnetCHARTING.dll添加到工具箱,並且添加引用;
2.把控件拖到你的網頁上,然後添加引用using dotnetCHARTING;就可以用了;
3.接下來是自己寫的對DotNetCharting操作的封裝類,以便於在程序裏調用。
- ShowData.cs
- using System;
- using System.Data;
- using System.Text;
- using dotnetCHARTING;
- namespace FLX.ComplexQuery
- {
- /**//// <summary>
- /// 彭建軍
- /// 根據數據動態生成圖形(柱形圖、餅圖、曲線圖)
- /// 2008-06-19
- /// </summary>
- public class ShowData
- {
- 屬性#region 屬性
- private string _phaysicalimagepath;//圖片存放路徑
- private string _title; //圖片標題
- private string _xtitle;//圖片x座標名稱
- private string _ytitle;//圖片y座標名稱
- private string _seriesname;//圖例名稱
- private int _picwidth;//圖片寬度
- private int _pichight;//圖片高度
- private DataTable _dt;//圖片數據源
- /**//// <summary>
- /// 圖片存放路徑
- /// </summary>
- public string PhaysicalImagePath
- {
- set{_phaysicalimagepath=value;}
- get{return _phaysicalimagepath;}
- }
- /**//// <summary>
- /// 圖片標題
- /// </summary>
- public string Title
- {
- set{_title=value;}
- get{return _title;}
- }
- /**//// <summary>
- /// 圖片標題
- /// </summary>
- public string XTitle
- {
- set{_xtitle=value;}
- get{return _xtitle;}
- }
- /**//// <summary>
- /// 圖片標題
- /// </summary>
- public string YTitle
- {
- set{_ytitle=value;}
- get{return _ytitle;}
- }
- /**//// <summary>
- /// 圖例名稱
- /// </summary>
- public string SeriesName
- {
- set{_seriesname=value;}
- get{return _seriesname;}
- }
- /**//// <summary>
- /// 圖片寬度
- /// </summary>
- public int PicWidth
- {
- set{_picwidth=value;}
- get{return _picwidth;}
- }
- /**//// <summary>
- /// 圖片高度
- /// </summary>
- public int PicHight
- {
- set{_pichight=value;}
- get{return _pichight;}
- }
- /**//// <summary>
- /// 圖片數據源
- /// </summary>
- public DataTable DataSource
- {
- set{_dt=value; }
- get{return _dt;}
- }
- #endregion
- 構造函數#region 構造函數
- public ShowData()
- {
- //
- // TODO: 在此處添加構造函數邏輯
- //
- }
- public ShowData(string PhaysicalImagePath,string Title,string XTitle,string YTitle,string SeriesName)
- {
- _phaysicalimagepath=PhaysicalImagePath;
- _title=Title;
- _xtitle=XTitle;
- _ytitle=YTitle;
- _seriesname=SeriesName;
- }
- #endregion
- 輸出柱形圖#region 輸出柱形圖
- /**//// <summary>
- /// 柱形圖
- /// </summary>
- /// <returns></returns>
- public void CreateColumn(dotnetCHARTING.Chart chart)
- {
- chart.Title=this._title;
- chart.XAxis.Label.Text=this._xtitle;
- chart.YAxis.Label.Text=this._ytitle;
- chart.TempDirectory =this._phaysicalimagepath;
- chart.Width = this._picwidth;
- chart.Height = this._pichight;
- chart.Type = ChartType.Combo ;
- chart.Series.Type =SeriesType.Cylinder;
- chart.Series.Name = this._seriesname;
- chart.Series.Data = this._dt;
- chart.SeriesCollection.Add();
- chart.DefaultSeries.DefaultElement.ShowValue = true;
- chart.ShadingEffect = true;
- chart.Use3D = false;
- chart.Series.DefaultElement.ShowValue =true;
- }
- #endregion
- 輸出餅圖#region 輸出餅圖
- /**//// <summary>
- /// 餅圖
- /// </summary>
- /// <returns></returns>
- public void CreatePie(dotnetCHARTING.Chart chart)
- {
- chart.Title=this._title;
- chart.TempDirectory =this._phaysicalimagepath;
- chart.Width = this._picwidth;
- chart.Height = this._pichight;
- chart.Type = ChartType.Pie;
- chart.Series.Type =SeriesType.Cylinder;
- chart.Series.Name = this._seriesname;
- chart.ShadingEffect = true;
- chart.Use3D = false;
- chart.DefaultSeries.DefaultElement.Transparency = 20;
- chart.DefaultSeries.DefaultElement.ShowValue = true;
- chart.PieLabelMode = PieLabelMode.Outside;
- chart.SeriesCollection.Add(getArrayData());
- chart.Series.DefaultElement.ShowValue = true;
- }
- private SeriesCollection getArrayData()
- {
- SeriesCollection SC = new SeriesCollection();
- DataTable dt = this._dt;
- for(int i=0; i < dt.Rows.Count; i++)
- {
- Series s = new Series();
- s.Name = dt.Rows[i][0].ToString();
- Element e = new Element();
- // 每元素的名稱
- e.Name = dt.Rows[i][0].ToString();
- // 每元素的大小數值
- e.YValue=Convert.ToInt32(dt.Rows[i][1].ToString());
- s.Elements.Add(e);
- SC.Add(s);
- }
- return SC;
- }
- #endregion
- 輸出曲線圖#region 輸出曲線圖
- /**//// <summary>
- /// 曲線圖
- /// </summary>
- /// <returns></returns>
- public void CreateLine(dotnetCHARTING.Chart chart)
- {
- chart.Title=this._title;
- chart.XAxis.Label.Text=this._xtitle;
- chart.YAxis.Label.Text=this._ytitle;
- chart.TempDirectory =this._phaysicalimagepath;
- chart.Width = this._picwidth;
- chart.Height = this._pichight;
- chart.Type = ChartType.Combo ;
- chart.Series.Type =SeriesType.Line;
- chart.Series.Name = this._seriesname;
- chart.Series.Data = this._dt;
- chart.SeriesCollection.Add();
- chart.DefaultSeries.DefaultElement.ShowValue = true;
- chart.ShadingEffect = true;
- chart.Use3D = false;
- chart.Series.DefaultElement.ShowValue =true;
- }
- #endregion
- 調用說明及範例#region 調用說明及範例
- // 在要顯示統計圖的頁面代碼直接調用,方法類似如下:
- //
- // ShowData show=new ShowData();
- // show.Title ="2008年各月消費情況統計";
- // show.XTitle ="月份";
- // show.YTitle ="金額(萬元)";
- // show.PicHight =300;
- // show.PicWidth =600;
- // show.SeriesName ="具體詳情";
- // show.PhaysicalImagePath ="ChartImages";
- // show.DataSource =this.GetDataSource();
- // show.CreateColumn(this.Chart1);
- #endregion
- }
- }
效果圖展示:
1、餅圖
2、柱形圖
3、曲線圖
補充:
帖子發了一天,沒人回答我多維統計圖的實現方式,只好自己去dotnetcharting的官方網站下載了最新的dotnetcharting控件,在 dotnetcharting控件的使用說明文檔中詳細地介紹了各種多維統計圖的實現方式。現把說明文檔貼出來供大家下載
dotnetcharting使用說明文檔
追加補充新內容:
1、解決“每運行一次DotNetCharting頁面,就會生成一個圖片,這樣圖片不是越來越多嗎?請問怎樣自動刪除DotNetCharting生成的圖片呢”的問題,參照asp.net刪除文件夾裏的所有文件 。
2、解決“(1)生成的圖片帶超鏈接導向官網,如何處理呀?(2)我使用這個控件後,圖形可以顯示出來。但是發現一個小問題。就是在圖形的左上方和圖形的下面都隱含了超鏈接,鼠標移動到這兩個區域後,點擊都會鏈接到http://www.dotnetcharting.com/。很奇怪,這是和破解有管嗎?”等類似的問題,參照DotnetCharting控件各版本破解方法 。