dotNetCharting使用总结

dotNetCharting使用

 

dotnetcharting是一款商务图表控件,若要使用,需要破解,或者下个破解版本。

dotnetcharting可用于web和winform,有对应的web版本DLL和winform版本DLL。

以下贴出在winform中使用方法。如有需要此破解版的DLL,可与我联系,无偿奉献。

首先贴出效果图

一、折线图

曲线图:

 

柱状图:

 

 饼状图:

下面看代码:

建一个通用Charting类

[c-sharp]  view plain  copy
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Text;  
  4. using System.Data ;  
  5. //using dotnetCHARTING;  
  6. using dotnetCHARTING.WinForms;  
  7. namespace Common  
  8. {  
  9.     public class Charting  
  10.     {  
  11.         private string _phaysicalimagepath;//图片存放路径  
  12.         private string _title; //图片标题  
  13.         private string _xtitle;//图片x座标名称  
  14.         private string _ytitle;//图片y座标名称  
  15.         private string _seriesname;//图例名称  
  16.         private int _picwidth;//图片宽度  
  17.         private int _pichight;//图片高度  
  18.         private MyChartType  _type;//统计图类型(柱形,线形等)  
  19.         private bool _use3d;//是否显示成3维图片  
  20.         private SeriesCollection _dt;//统计图数据源  
  21.         private string _filename;//统计图片的名称(不包括后缀名)  
  22.   
  23.         /**/  
  24.         /// <summary>  
  25.         /// 图片存放路径  
  26.         /// </summary>  
  27.         public string PhaysicalImagePath  
  28.         {  
  29.             set { _phaysicalimagepath = value; }  
  30.             get { return _phaysicalimagepath; }  
  31.         }  
  32.         /**/  
  33.         /// <summary>  
  34.         /// 图片标题  
  35.         /// </summary>  
  36.         public string Title  
  37.         {  
  38.             set { _title = value; }  
  39.             get { return _title; }  
  40.         }  
  41.         /**/  
  42.         /// <summary>  
  43.         /// 图片x座标名称  
  44.         /// </summary>  
  45.         public string XTitle  
  46.         {  
  47.             set { _xtitle = value; }  
  48.             get { return _xtitle; }  
  49.         }  
  50.         /**/  
  51.         /// <summary>  
  52.         /// 图片y座标名称  
  53.         /// </summary>  
  54.         public string YTitle  
  55.         {  
  56.             set { _ytitle = value; }  
  57.             get { return _ytitle; }  
  58.         }  
  59.   
  60.         /**/  
  61.         /// <summary>  
  62.         /// 图例名称  
  63.         /// </summary>  
  64.         public string SeriesName  
  65.         {  
  66.             set { _seriesname = value; }  
  67.             get { return _seriesname; }  
  68.         }  
  69.         /**/  
  70.         /// <summary>  
  71.         /// 图片宽度  
  72.         /// </summary>  
  73.         public int PicWidth  
  74.         {  
  75.             set { _picwidth = value; }  
  76.             get { return _picwidth; }  
  77.         }  
  78.         /**/  
  79.         /// <summary>  
  80.         /// 图片高度  
  81.         /// </summary>  
  82.         public int PicHight  
  83.         {  
  84.             set { _pichight = value; }  
  85.             get { return _pichight; }  
  86.         }  
  87.   
  88.         /// <summary>  
  89.         /// 统计图类型(柱形,线形等)  
  90.         /// </summary>  
  91.         public MyChartType Type  
  92.         {  
  93.             set { _type = value; }  
  94.             get { return _type; }  
  95.         }  
  96.   
  97.         /// <summary>  
  98.         /// 是否将输出的图片显示成三维  
  99.         /// </summary>  
  100.         public bool Use3D  
  101.         {  
  102.             set { _use3d = value; }  
  103.             get { return _use3d; }  
  104.         }  
  105.   
  106.         /// <summary>  
  107.         /// 对比图形数据源  
  108.         /// </summary>  
  109.         public SeriesCollection DataSource  
  110.         {  
  111.   
  112.             set { _dt = value; }  
  113.             get { return _dt; }  
  114.         }  
  115.   
  116.         /// <summary>  
  117.         /// 生成统计图片的名称  
  118.         /// </summary>  
  119.         public string FileName  
  120.         {  
  121.             set { _filename = value; }  
  122.             get { return _filename; }  
  123.         }  
  124.   
  125.   
  126.         /// <summary>  
  127.         /// 生成统计图片  
  128.         /// </summary>  
  129.         /// <param name="chart"></param>  
  130.         /// <param name="type">图形类别,如柱状,折线型</param>  
  131.         public void CreateStatisticPic(dotnetCHARTING .WinForms.Chart chart)  
  132.         {  
  133.             chart.SeriesCollection.Clear();  
  134.             chart.Title = this.Title;  
  135.             chart.XAxis.Label.Text = this.XTitle;  
  136.             chart.YAxis.Label.Text = this.YTitle;  
  137.             chart.TempDirectory = this.PhaysicalImagePath;  
  138.             chart.FileManager.FileName = this.FileName;  
  139.             chart.Width = this.PicWidth;  
  140.             chart.Height = this.PicHight;  
  141.             if (this.Type == MyChartType.Pie)  
  142.             {  
  143.                 chart.Type = ChartType.Pie;  
  144.                 chart.Use3D = true ;  
  145.                 chart.PieLabelMode = PieLabelMode.Outside;  
  146.                 chart.DefaultSeries.DefaultElement.Transparency = 5;   
  147.   
  148.             }  
  149.             else  
  150.             {  
  151.                 chart.Type = ChartType.Combo;  
  152.                 SeriesType st = (SeriesType)this.Type;  
  153.                 chart.DefaultSeries.Type = st; //统一使用默认的序列图类型属性  
  154.                 chart.Use3D = this.Use3D;  
  155.             }  
  156.             //chart.Series.Type = this.Type;//生成对比的线型图时不适用  
  157.               
  158.             chart.Series.Name = this.SeriesName;  
  159.             chart.SeriesCollection.Add(this.DataSource);  
  160.             //chart.Series.Data = this.DataSource;  
  161.             chart.DefaultSeries.DefaultElement.ShowValue = true;  
  162.             chart.ShadingEffect = true;  
  163.           
  164.             chart.Series.DefaultElement.ShowValue = true;  
  165.   
  166.             chart.Refresh();  
  167.         }  
  168.         public enum MyChartType  
  169.         {  
  170.             Marker = 1,  
  171.             Spline = 2,  
  172.             Line = 3,  
  173.             AreaLine = 4,  
  174.             Column = 5,  
  175.             Cylinder = 6,  
  176.             Bar = 7,  
  177.             Bubble = 8,  
  178.             AreaSpline = 9,  
  179.             Pyramid = 10,  
  180.             Cone = 11,  
  181.             BubbleShape = 12,  
  182.             BarSegmented = 13,  
  183.             Pie=14  
  184.         }  
  185.   
  186.     }  
  187. }  

在winform的界面工具栏右键添加控件dotnetcharing.

在目标界面拖一个dotnetcharing控件

 

以下是数据源为datatable类型的界面代码

[c-sharp]  view plain  copy
  1.         private void Drawing(DataTable dt, DrawType type)  
  2.         {  
  3.             Common.Charting c = new Common.Charting();  
  4.             c.Title = dtpst.Value.ToString() + "至" + dtpend.Value.ToString() + (type == DrawType.Storage ? "B2B人员MF出库总量统计图" : "B2B人员MF出库总金额统计图");  
  5.             c.XTitle = "日期";  
  6.             c.YTitle = (type == DrawType.Storage ? "出库总量" : "出库总金额");  
  7.             if (type == DrawType.Storage)  
  8.             {  
  9.                 int height = (int)nudvalueH.Value;  
  10.                 //int width = (int)nudvalueW.Value;  
  11.                 panelValue.Height = height;  
  12.                 //panelValue.Width = width;  
  13.                 c.PicHight = panelValue.Height - 50;  
  14.                 //c.PicWidth = panelValue.Width - 50;  
  15.                 if (rbtnValuePie.Checked)  
  16.                     c.Type = Common.Charting.MyChartType.Pie;  
  17.                 else if (rbtnValueCylinder.Checked)  
  18.                     c.Type = Common.Charting.MyChartType.Cylinder;  
  19.                 else if (rbtnValueSpline.Checked)  
  20.                     c.Type = Common.Charting.MyChartType.Spline;  
  21.                 else if (rbtnValueLine.Checked)  
  22.                     c.Type = Common.Charting.MyChartType.Line;  
  23.             }  
  24.             else  
  25.             {  
  26.                 int height = (int)nudPriceH.Value;  
  27.                 //int width = (int)nudPriceW.Value;  
  28.                 panelprice.Height = height;  
  29.                 //panelprice.Width = width;  
  30.                 c.PicHight = panelprice.Height - 50;  
  31.                 //c.PicWidth = panelprice.Width - 50;  
  32.                 if (rbtnPricePie.Checked)  
  33.                     c.Type = Common.Charting.MyChartType.Pie;  
  34.                 else if (rbtnPriceCylinder.Checked)  
  35.                     c.Type = Common.Charting.MyChartType.Cylinder;  
  36.                 else if (this.rbtnPriceSpline.Checked)  
  37.                     c.Type = Common.Charting.MyChartType.Spline;  
  38.                 else if (this.rbtnPriceLine.Checked)  
  39.                     c.Type = Common.Charting.MyChartType.Line;  
  40.             }  
  41.             c.SeriesName = "合计";//仅对于DataTable类型做数据源时,此属性有效  
  42.             c.PhaysicalImagePath = "StorageForm";//统计图片存放的文件夹名称,缺少对应的文件夹生成不了统计图片  
  43.             c.FileName = "StorageStatistics";  
  44.   
  45.             c.Use3D =(cbox3d .Checked==true?true : false);  
  46.             c.DataSource = GetDataSource(dt, type);//(c.Type == Common.Charting.MyChartType.Pie ? GetPieDataSource(dt, type) : GetDataSource(dt, type));  
  47.             dotnetCHARTING.WinForms.Chart chart = (type == DrawType.Storage ? chartValue : chartprice);  
  48.             c.CreateStatisticPic(chart);  
  49.   
  50.   
  51.         }  
  52.         private SeriesCollection GetDataSource(DataTable dt, DrawType type)  
  53.         {  
  54.             SeriesCollection sc = new SeriesCollection();  
  55.   
  56.             Series skucun = new Series();  
  57.             Series sfeikucun = new Series();  
  58.             skucun.Name = (type == DrawType.Storage ? "走库存" : "走库存");  
  59.             sfeikucun.Name = (type == DrawType.Storage ? "走非库存" : "走非库存");  
  60.             DataView dv = dt.DefaultView;  
  61.             dv.Sort = "Date asc";  
  62.             dt = dv.ToTable();  
  63.             for (int i = 0; i < dt.Rows.Count; i++)  
  64.             {  
  65.                 Element e = new Element();  
  66.                 Element efei = new Element();  
  67.                 e.Name = ((DateTime)dt.Rows[i]["Date"]).Month.ToString() + "/" + ((DateTime)dt.Rows[i]["Date"]).Day.ToString();  
  68.                 efei.Name = ((DateTime)dt.Rows[i]["Date"]).Month.ToString() + "/" + ((DateTime)dt.Rows[i]["Date"]).Day.ToString();  
  69.                 e.YValue = double.Parse((type == DrawType.Storage ? dt.Rows[i]["KuStorageValue"].ToString()+"0" : dt.Rows[i]["KuStoragePrice"].ToString()+"0"));  
  70.                 efei.YValue = double.Parse((type == DrawType.Storage ? dt.Rows[i]["FeiStorageValue"].ToString() +"0": dt.Rows[i]["FeiStoragePrice"].ToString()+"0"));  
  71.                 skucun.AddElements(e);  
  72.                 sfeikucun.AddElements(efei);  
  73.             }  
  74.   
  75.             sc.Add(skucun); sc.Add(sfeikucun);  
  76.               
  77.             return sc;  
  78.         }  
  79.   
  80. private enum DrawType  
  81.         {  
  82.             Storage = 1,  
  83.             AvgPrice = 2  
  84.         }  

另外还有区域图,在此就不贴出来了,不管是什么图形,均可用上面的通用代码~每天进步一点步~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值