dotNetCharting使用
dotnetcharting是一款商务图表控件,若要使用,需要破解,或者下个破解版本。
dotnetcharting可用于web和winform,有对应的web版本DLL和winform版本DLL。
以下贴出在winform中使用方法。如有需要此破解版的DLL,可与我联系,无偿奉献。
首先贴出效果图
一、折线图
曲线图:
柱状图:
饼状图:
下面看代码:
建一个通用Charting类
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Data ;
- //using dotnetCHARTING;
- using dotnetCHARTING.WinForms;
- namespace Common
- {
- public class Charting
- {
- private string _phaysicalimagepath;//图片存放路径
- private string _title; //图片标题
- private string _xtitle;//图片x座标名称
- private string _ytitle;//图片y座标名称
- private string _seriesname;//图例名称
- private int _picwidth;//图片宽度
- private int _pichight;//图片高度
- private MyChartType _type;//统计图类型(柱形,线形等)
- private bool _use3d;//是否显示成3维图片
- private SeriesCollection _dt;//统计图数据源
- private string _filename;//统计图片的名称(不包括后缀名)
- /**/
- /// <summary>
- /// 图片存放路径
- /// </summary>
- public string PhaysicalImagePath
- {
- set { _phaysicalimagepath = value; }
- get { return _phaysicalimagepath; }
- }
- /**/
- /// <summary>
- /// 图片标题
- /// </summary>
- public string Title
- {
- set { _title = value; }
- get { return _title; }
- }
- /**/
- /// <summary>
- /// 图片x座标名称
- /// </summary>
- public string XTitle
- {
- set { _xtitle = value; }
- get { return _xtitle; }
- }
- /**/
- /// <summary>
- /// 图片y座标名称
- /// </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 MyChartType Type
- {
- set { _type = value; }
- get { return _type; }
- }
- /// <summary>
- /// 是否将输出的图片显示成三维
- /// </summary>
- public bool Use3D
- {
- set { _use3d = value; }
- get { return _use3d; }
- }
- /// <summary>
- /// 对比图形数据源
- /// </summary>
- public SeriesCollection DataSource
- {
- set { _dt = value; }
- get { return _dt; }
- }
- /// <summary>
- /// 生成统计图片的名称
- /// </summary>
- public string FileName
- {
- set { _filename = value; }
- get { return _filename; }
- }
- /// <summary>
- /// 生成统计图片
- /// </summary>
- /// <param name="chart"></param>
- /// <param name="type">图形类别,如柱状,折线型</param>
- public void CreateStatisticPic(dotnetCHARTING .WinForms.Chart chart)
- {
- chart.SeriesCollection.Clear();
- chart.Title = this.Title;
- chart.XAxis.Label.Text = this.XTitle;
- chart.YAxis.Label.Text = this.YTitle;
- chart.TempDirectory = this.PhaysicalImagePath;
- chart.FileManager.FileName = this.FileName;
- chart.Width = this.PicWidth;
- chart.Height = this.PicHight;
- if (this.Type == MyChartType.Pie)
- {
- chart.Type = ChartType.Pie;
- chart.Use3D = true ;
- chart.PieLabelMode = PieLabelMode.Outside;
- chart.DefaultSeries.DefaultElement.Transparency = 5;
- }
- else
- {
- chart.Type = ChartType.Combo;
- SeriesType st = (SeriesType)this.Type;
- chart.DefaultSeries.Type = st; //统一使用默认的序列图类型属性
- chart.Use3D = this.Use3D;
- }
- //chart.Series.Type = this.Type;//生成对比的线型图时不适用
- chart.Series.Name = this.SeriesName;
- chart.SeriesCollection.Add(this.DataSource);
- //chart.Series.Data = this.DataSource;
- chart.DefaultSeries.DefaultElement.ShowValue = true;
- chart.ShadingEffect = true;
- chart.Series.DefaultElement.ShowValue = true;
- chart.Refresh();
- }
- public enum MyChartType
- {
- Marker = 1,
- Spline = 2,
- Line = 3,
- AreaLine = 4,
- Column = 5,
- Cylinder = 6,
- Bar = 7,
- Bubble = 8,
- AreaSpline = 9,
- Pyramid = 10,
- Cone = 11,
- BubbleShape = 12,
- BarSegmented = 13,
- Pie=14
- }
- }
- }
在winform的界面工具栏右键添加控件dotnetcharing.
在目标界面拖一个dotnetcharing控件
以下是数据源为datatable类型的界面代码
- private void Drawing(DataTable dt, DrawType type)
- {
- Common.Charting c = new Common.Charting();
- c.Title = dtpst.Value.ToString() + "至" + dtpend.Value.ToString() + (type == DrawType.Storage ? "B2B人员MF出库总量统计图" : "B2B人员MF出库总金额统计图");
- c.XTitle = "日期";
- c.YTitle = (type == DrawType.Storage ? "出库总量" : "出库总金额");
- if (type == DrawType.Storage)
- {
- int height = (int)nudvalueH.Value;
- //int width = (int)nudvalueW.Value;
- panelValue.Height = height;
- //panelValue.Width = width;
- c.PicHight = panelValue.Height - 50;
- //c.PicWidth = panelValue.Width - 50;
- if (rbtnValuePie.Checked)
- c.Type = Common.Charting.MyChartType.Pie;
- else if (rbtnValueCylinder.Checked)
- c.Type = Common.Charting.MyChartType.Cylinder;
- else if (rbtnValueSpline.Checked)
- c.Type = Common.Charting.MyChartType.Spline;
- else if (rbtnValueLine.Checked)
- c.Type = Common.Charting.MyChartType.Line;
- }
- else
- {
- int height = (int)nudPriceH.Value;
- //int width = (int)nudPriceW.Value;
- panelprice.Height = height;
- //panelprice.Width = width;
- c.PicHight = panelprice.Height - 50;
- //c.PicWidth = panelprice.Width - 50;
- if (rbtnPricePie.Checked)
- c.Type = Common.Charting.MyChartType.Pie;
- else if (rbtnPriceCylinder.Checked)
- c.Type = Common.Charting.MyChartType.Cylinder;
- else if (this.rbtnPriceSpline.Checked)
- c.Type = Common.Charting.MyChartType.Spline;
- else if (this.rbtnPriceLine.Checked)
- c.Type = Common.Charting.MyChartType.Line;
- }
- c.SeriesName = "合计";//仅对于DataTable类型做数据源时,此属性有效
- c.PhaysicalImagePath = "StorageForm";//统计图片存放的文件夹名称,缺少对应的文件夹生成不了统计图片
- c.FileName = "StorageStatistics";
- c.Use3D =(cbox3d .Checked==true?true : false);
- c.DataSource = GetDataSource(dt, type);//(c.Type == Common.Charting.MyChartType.Pie ? GetPieDataSource(dt, type) : GetDataSource(dt, type));
- dotnetCHARTING.WinForms.Chart chart = (type == DrawType.Storage ? chartValue : chartprice);
- c.CreateStatisticPic(chart);
- }
- private SeriesCollection GetDataSource(DataTable dt, DrawType type)
- {
- SeriesCollection sc = new SeriesCollection();
- Series skucun = new Series();
- Series sfeikucun = new Series();
- skucun.Name = (type == DrawType.Storage ? "走库存" : "走库存");
- sfeikucun.Name = (type == DrawType.Storage ? "走非库存" : "走非库存");
- DataView dv = dt.DefaultView;
- dv.Sort = "Date asc";
- dt = dv.ToTable();
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- Element e = new Element();
- Element efei = new Element();
- e.Name = ((DateTime)dt.Rows[i]["Date"]).Month.ToString() + "/" + ((DateTime)dt.Rows[i]["Date"]).Day.ToString();
- efei.Name = ((DateTime)dt.Rows[i]["Date"]).Month.ToString() + "/" + ((DateTime)dt.Rows[i]["Date"]).Day.ToString();
- e.YValue = double.Parse((type == DrawType.Storage ? dt.Rows[i]["KuStorageValue"].ToString()+"0" : dt.Rows[i]["KuStoragePrice"].ToString()+"0"));
- efei.YValue = double.Parse((type == DrawType.Storage ? dt.Rows[i]["FeiStorageValue"].ToString() +"0": dt.Rows[i]["FeiStoragePrice"].ToString()+"0"));
- skucun.AddElements(e);
- sfeikucun.AddElements(efei);
- }
- sc.Add(skucun); sc.Add(sfeikucun);
- return sc;
- }
- private enum DrawType
- {
- Storage = 1,
- AvgPrice = 2
- }
另外还有区域图,在此就不贴出来了,不管是什么图形,均可用上面的通用代码~每天进步一点步~