C#.net使用DotNetCharting控件生成報表統計圖--A

在做項目時要對數據進行統計分析,所以必須生成一些報表統計圖(如柱形圖、餅圖、曲線圖等),網上強烈推薦了使用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操作的封裝類,以便於在程序裏調用。

 

  1. ShowData.cs  
  2. using System;  
  3. using System.Data;  
  4. using System.Text;  
  5. using dotnetCHARTING;  
  6.   
  7. namespace FLX.ComplexQuery  
  8. {  
  9.     /**//// <summary>      
  10.     /// 彭建軍  
  11.     /// 根據數據動態生成圖形(柱形圖、餅圖、曲線圖)  
  12.     /// 2008-06-19  
  13.     /// </summary>  
  14.     public class ShowData  
  15.     {  
  16.   
  17.         屬性#region 屬性  
  18.         private string _phaysicalimagepath;//圖片存放路徑  
  19.         private string _title; //圖片標題  
  20.         private string _xtitle;//圖片x座標名稱  
  21.         private string _ytitle;//圖片y座標名稱  
  22.         private string _seriesname;//圖例名稱  
  23.         private int _picwidth;//圖片寬度  
  24.         private int _pichight;//圖片高度  
  25.         private DataTable _dt;//圖片數據源  
  26.   
  27.         /**//// <summary>  
  28.         /// 圖片存放路徑  
  29.         /// </summary>  
  30.         public string PhaysicalImagePath  
  31.         {  
  32.             set{_phaysicalimagepath=value;}  
  33.             get{return _phaysicalimagepath;}  
  34.         }  
  35.         /**//// <summary>  
  36.         /// 圖片標題  
  37.         /// </summary>  
  38.         public string Title  
  39.         {  
  40.             set{_title=value;}  
  41.             get{return _title;}  
  42.         }  
  43.         /**//// <summary>  
  44.         /// 圖片標題  
  45.         /// </summary>  
  46.         public string XTitle  
  47.         {  
  48.             set{_xtitle=value;}  
  49.             get{return _xtitle;}  
  50.         }  
  51.         /**//// <summary>  
  52.         /// 圖片標題  
  53.         /// </summary>  
  54.         public string YTitle  
  55.         {  
  56.             set{_ytitle=value;}  
  57.             get{return _ytitle;}  
  58.         }  
  59.   
  60.         /**//// <summary>  
  61.         /// 圖例名稱  
  62.         /// </summary>  
  63.         public string SeriesName  
  64.         {  
  65.             set{_seriesname=value;}  
  66.             get{return _seriesname;}  
  67.         }  
  68.         /**//// <summary>  
  69.         /// 圖片寬度  
  70.         /// </summary>  
  71.         public int PicWidth  
  72.         {  
  73.             set{_picwidth=value;}  
  74.             get{return _picwidth;}  
  75.         }  
  76.         /**//// <summary>  
  77.         /// 圖片高度  
  78.         /// </summary>  
  79.         public int PicHight  
  80.         {  
  81.             set{_pichight=value;}  
  82.             get{return _pichight;}  
  83.         }  
  84.         /**//// <summary>  
  85.         /// 圖片數據源  
  86.         /// </summary>  
  87.         public DataTable DataSource  
  88.         {  
  89.             set{_dt=value; }  
  90.             get{return _dt;}  
  91.         }  
  92.         #endregion  
  93.   
  94.         構造函數#region 構造函數  
  95.         public ShowData()  
  96.         {  
  97.             //  
  98.             // TODO: 在此處添加構造函數邏輯  
  99.             //  
  100.         }  
  101.           
  102.         public ShowData(string PhaysicalImagePath,string Title,string XTitle,string YTitle,string SeriesName)  
  103.         {  
  104.             _phaysicalimagepath=PhaysicalImagePath;  
  105.             _title=Title;  
  106.             _xtitle=XTitle;  
  107.             _ytitle=YTitle;  
  108.             _seriesname=SeriesName;    
  109.         }  
  110.         #endregion  
  111.   
  112.         輸出柱形圖#region 輸出柱形圖  
  113.         /**//// <summary>  
  114.         /// 柱形圖  
  115.         /// </summary>  
  116.         /// <returns></returns>  
  117.         public void CreateColumn(dotnetCHARTING.Chart chart)  
  118.         {   
  119.             chart.Title=this._title;          
  120.             chart.XAxis.Label.Text=this._xtitle;  
  121.             chart.YAxis.Label.Text=this._ytitle;  
  122.             chart.TempDirectory =this._phaysicalimagepath;          
  123.             chart.Width = this._picwidth;  
  124.             chart.Height = this._pichight;  
  125.             chart.Type = ChartType.Combo ;              
  126.             chart.Series.Type =SeriesType.Cylinder;  
  127.             chart.Series.Name = this._seriesname;                      
  128.             chart.Series.Data = this._dt;  
  129.             chart.SeriesCollection.Add();     
  130.             chart.DefaultSeries.DefaultElement.ShowValue = true;      
  131.             chart.ShadingEffect = true;      
  132.             chart.Use3D = false;      
  133.             chart.Series.DefaultElement.ShowValue =true;  
  134.         }  
  135.         #endregion  
  136.   
  137.         輸出餅圖#region 輸出餅圖  
  138.         /**//// <summary>  
  139.         /// 餅圖  
  140.         /// </summary>  
  141.         /// <returns></returns>  
  142.         public void CreatePie(dotnetCHARTING.Chart chart)  
  143.         {  
  144.             chart.Title=this._title;      
  145.             chart.TempDirectory =this._phaysicalimagepath;          
  146.             chart.Width = this._picwidth;  
  147.             chart.Height = this._pichight;  
  148.             chart.Type = ChartType.Pie;              
  149.             chart.Series.Type =SeriesType.Cylinder;  
  150.             chart.Series.Name = this._seriesname;                
  151.               
  152.             chart.ShadingEffect = true;      
  153.             chart.Use3D = false;              
  154.             chart.DefaultSeries.DefaultElement.Transparency = 20;   
  155.             chart.DefaultSeries.DefaultElement.ShowValue = true;  
  156.             chart.PieLabelMode = PieLabelMode.Outside;              
  157.             chart.SeriesCollection.Add(getArrayData());  
  158.             chart.Series.DefaultElement.ShowValue = true;   
  159.         }  
  160.   
  161.         private SeriesCollection getArrayData()          
  162.         {  
  163.             SeriesCollection SC = new SeriesCollection();  
  164.             DataTable dt = this._dt;  
  165.   
  166.             for(int i=0; i < dt.Rows.Count; i++)  
  167.             {  
  168.                 Series s = new Series();  
  169.                 s.Name = dt.Rows[i][0].ToString();      
  170.                   
  171.                 Element e = new Element();  
  172.   
  173.                 // 每元素的名稱  
  174.                 e.Name = dt.Rows[i][0].ToString();  
  175.   
  176.                 // 每元素的大小數值  
  177.                 e.YValue=Convert.ToInt32(dt.Rows[i][1].ToString());  
  178.                             
  179.                 s.Elements.Add(e);  
  180.                 SC.Add(s);  
  181.             }  
  182.             return SC;  
  183.         }  
  184.         #endregion  
  185.   
  186.         輸出曲線圖#region 輸出曲線圖  
  187.         /**//// <summary>  
  188.         /// 曲線圖  
  189.         /// </summary>  
  190.         /// <returns></returns>  
  191.         public void CreateLine(dotnetCHARTING.Chart chart)  
  192.         {               
  193.             chart.Title=this._title;          
  194.             chart.XAxis.Label.Text=this._xtitle;  
  195.             chart.YAxis.Label.Text=this._ytitle;  
  196.             chart.TempDirectory =this._phaysicalimagepath;          
  197.             chart.Width = this._picwidth;  
  198.             chart.Height = this._pichight;  
  199.             chart.Type = ChartType.Combo ;              
  200.             chart.Series.Type =SeriesType.Line;  
  201.             chart.Series.Name = this._seriesname;                      
  202.             chart.Series.Data = this._dt;  
  203.             chart.SeriesCollection.Add();     
  204.             chart.DefaultSeries.DefaultElement.ShowValue = true;      
  205.             chart.ShadingEffect = true;      
  206.             chart.Use3D = false;      
  207.             chart.Series.DefaultElement.ShowValue =true;  
  208.         }  
  209.         #endregion  
  210.   
  211.         調用說明及範例#region 調用說明及範例  
  212.         //        在要顯示統計圖的頁面代碼直接調用,方法類似如下:  
  213.         //  
  214. //        ShowData show=new ShowData();     
  215. //        show.Title ="2008年各月消費情況統計";  
  216. //        show.XTitle ="月份";  
  217. //        show.YTitle ="金額(萬元)";  
  218. //        show.PicHight =300;  
  219. //        show.PicWidth =600;  
  220. //        show.SeriesName ="具體詳情";  
  221. //        show.PhaysicalImagePath ="ChartImages";  
  222. //        show.DataSource =this.GetDataSource();  
  223. //        show.CreateColumn(this.Chart1);      
  224.         #endregion  
  225.   
  226.     }  
  227. }  

 

 效果圖展示:
     1、餅圖

     2、柱形圖


     3、曲線圖
      
    補充:
    帖子發了一天,沒人回答我多維統計圖的實現方式,只好自己去dotnetcharting的官方網站下載了最新的dotnetcharting控件,在 dotnetcharting控件的使用說明文檔中詳細地介紹了各種多維統計圖的實現方式。現把說明文檔貼出來供大家下載
    dotnetcharting使用說明文檔

     追加補充新內容:
     1、解決“每運行一次DotNetCharting頁面,就會生成一個圖片,這樣圖片不是越來越多嗎?請問怎樣自動刪除DotNetCharting生成的圖片呢”的問題,參照asp.net刪除文件夾裏的所有文件 。

     2、解決“(1)生成的圖片帶超鏈接導向官網,如何處理呀?(2)我使用這個控件後,圖形可以顯示出來。但是發現一個小問題。就是在圖形的左上方和圖形的下面都隱含了超鏈接,鼠標移動到這兩個區域後,點擊都會鏈接到http://www.dotnetcharting.com/。很奇怪,這是和破解有管嗎?”等類似的問題,參照DotnetCharting控件各版本破解方法 。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章