• C#.net使用DotNetCharting控件生成报表统计图


    在做项目时要对数据进行统计分析,所以必须生成一些报表统计图(如柱形图、饼图、曲线图等),网上强烈推荐了使用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. }  

     效果图展示:

        补充:
        帖子发了一天,没人回答我多维统计图的实现方式,只好自己去dotnetcharting的官方网站下载了最新的dotnetcharting控件,在 dotnetcharting控件的使用说明文档中详细地介绍了各种多维统计图的实现方式。现把说明文档贴出来供大家下载
        dotnetcharting使用说明文档

         追加补充新内容:
         1、解决“每运行一次DotNetCharting页面,就会生成一个图片,这样图片不是越来越多吗?请问怎样自动删除DotNetCharting生成的图片呢”的问题,参照asp.net删除文件夹里的所有文件 。

         2、解决“(1)生成的图片带超链接导向官网,如何处理呀?(2)我使用这个控件后,图形可以显示出来。但是发现一个小问题。就是在图形的左上方和图形的下面都隐含了超链接,鼠标移动到这两个区域后,点击都会链接到http://www.dotnetcharting.com/。很奇怪,这是和破解有管吗?”等类似的问题,参照DotnetCharting控件各版本破解方法 。

  • 相关阅读:
    HTTP的连接过程
    查看mysql数据库及表编码格式
    spring quartz 的定时器cronExpression表达式写法(转载)
    两种 js下载文件的步骤
    进制转换三(二进制、八进制、十进制、十六进制之间的转换)
    进制的转换二
    Tls版本
    读李笑来《把时间当做朋友》笔记
    postman批量编辑参数
    uml类关系常见图标的含义
  • 原文地址:https://www.cnblogs.com/jjg0519/p/8471570.html
Copyright © 2020-2023  润新知