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;//统计图片的名称(不包括后缀名) /**/ ///
在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 }
另外还有区域图,在此就不贴出来了,不管是什么图形,均可用上面的通用代码~每天进步一点步~