dotNetCharting使用总结
生活随笔
收集整理的這篇文章主要介紹了
dotNetCharting使用总结
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
dotNetCharting使用
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?? ????????}?? ?? ????}?? }?? ????????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?? ????????}??
?
dotnetcharting是一款商務圖表控件,若要使用,需要破解,或者下個破解版本。
dotnetcharting可用于web和winform,有對應的web版本DLL和winform版本DLL。
以下貼出在winform中使用方法。如有需要此破解版的DLL,可與我聯系,無償奉獻。
首先貼出效果圖
一、折線圖
曲線圖:
?
柱狀圖:
?
?餅狀圖:
下面看代碼:
建一個通用Charting類
[c-sharp]?view plaincopy在winform的界面工具欄右鍵添加控件dotnetcharing.
在目標界面拖一個dotnetcharing控件
?
以下是數據源為datatable類型的界面代碼
[c-sharp]?view plaincopy另外還有區域圖,在此就不貼出來了,不管是什么圖形,均可用上面的通用代碼~每天進步一點步~
總結
以上是生活随笔為你收集整理的dotNetCharting使用总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C# Chart控件,chart、Ser
- 下一篇: wireshark解析rtp协议,流媒体