接下來(lái)上干貨,前兩天剛使用dotnetcharting 做了個(gè)統(tǒng)計(jì)報(bào)表,代碼如下:using System;using System.Collections.Generic;using System.Data;using System.Drawing;using dotnetCHARTING.WinForms;using StationChart.Model;using StationChart.Utility;using Chart = dotnetCHARTING.WinForms.Chart;using Series = dotnetCHARTING.WinForms.Series;using SeriesCollection = dotnetCHARTING.WinForms.SeriesCollection;namespace ManageSystem{ // <summary> // 作者:薛江濤 // 版本:V1.0.0 // 時(shí)間:2014/10/9 11:49:48 // </summary> public class ShowData { #region 屬性 PRivate string _phaysicalimagepath;//圖片存放路徑 private string _xtitle;//圖片x座標(biāo)名稱 private string _ytitle;//圖片y座標(biāo)名稱 private string _seriesname;//圖例名稱 private int _picwidth;//圖片寬度 private int _pichight;//圖片高度 private DataTable _dt;//圖片數(shù)據(jù)源 private DataSet _ds;//圖片數(shù)據(jù)源 private Color _titleBoxColor;//圖片標(biāo)題背景色 private Font _titleBoxFont;//圖片標(biāo)題字體 private Color _chartAreaBackgroundColor;//圖片背景顏色 private Font _xAxisLabelFont;//X軸柱狀圖值字體 private Font _yAxisLabelFont;//Y軸柱狀圖值字體 private Font _xAxisDefaultTickLabelFont;//X軸刻度字體 private Font _yAxisDefaultTickLabelFont;//Y軸刻度字體 private SeriesType _chartDefaultSeriesType;//圖片類型 private ChartType _chartType;//圖片類型 //private bool _isMonth; //是否是月顯示 private int _staticColumnWidth;//設(shè)置柱狀圖每個(gè)單元格的寬度 private int _numberPercision;//設(shè)置數(shù)值小數(shù)點(diǎn) /// <summary> /// 圖片存放路徑 /// </summary> public string PhaysicalImagePath { set { _phaysicalimagepath = value; } get { return _phaysicalimagepath; } } /// <summary> /// 圖片標(biāo)題 /// </summary> public string Title { get; set; } /// <summary> /// 圖片標(biāo)題 /// </summary> public string XTitle { set { _xtitle = value; } get { return _xtitle; } } /// <summary> /// 圖片標(biāo)題 /// </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> /// 圖片數(shù)據(jù)源 /// </summary> public DataTable DataSource { set { _dt = value; } get { return _dt; } } /// <summary> /// 圖片數(shù)據(jù)源 /// </summary> public DataSet DataSetSource { set { _ds = value; } get { return _ds; } } public int NumberPercision { set { _numberPercision = value; } get { return _numberPercision; } } public Color TitleBoxColor { get { return _titleBoxColor; } set { _titleBoxColor = value; } } public Font TitleBoxFont { get { return _titleBoxFont; } set { _titleBoxFont = value; } } public Color ChartAreaBackgroundColor { get { return _chartAreaBackgroundColor; } set { _chartAreaBackgroundColor = value; } } public Font XAxisLabelFont { get { return _xAxisLabelFont; } set { _xAxisLabelFont = value; } } public Font YAxisLabelFont { get { return _yAxisLabelFont; } set { _yAxisLabelFont = value; } } public Font XAxisDefaultTickLabelFont { get { return _xAxisDefaultTickLabelFont; } set { _xAxisDefaultTickLabelFont = value; } } public Font YAxisDefaultTickLabelFont { get { return _yAxisDefaultTickLabelFont; } set { _yAxisDefaultTickLabelFont = value; } } public SeriesType ChartDefaultSeriesType { get { return _chartDefaultSeriesType; } set { _chartDefaultSeriesType = value; } } public ChartType ChartType { get { return _chartType; } set { _chartType = value; } } //public bool IsMonth //{ // get { return _isMonth; } // set { _isMonth = value; } //} public ModelConseme.DateChartEnum SeriesTypeE { get; set; } public int StaticColumnWidth { get { return _staticColumnWidth; } set { _staticColumnWidth = value; } } #endregion #region 構(gòu)造函數(shù) public ShowData() { // // TODO: 在此處添加構(gòu)造函數(shù)邏輯 // NumberPercision = 2; } public ShowData(string phaysicalImagePath, string title, string xTitle, string yTitle, string seriesName) { _phaysicalimagepath = phaysicalImagePath; Title = title; _xtitle = xTitle; _ytitle = yTitle; _seriesname = seriesName; } #endregion private static readonly object ThisLock = new object(); #region 輸出柱形圖 /// <summary> /// 柱形圖 /// </summary> /// <returns></returns> public void CreateColumn(Chart chart) { try { //清空?qǐng)D片 chart.SeriesCollection.Clear(); //標(biāo)題框設(shè)置 //標(biāo)題的顏色 chart.TitleBox.Label.Color = _titleBoxColor; //標(biāo)題字體設(shè)置 chart.TitleBox.Label.Font = _titleBoxFont; //控制柱狀圖顏色 chart.ShadingEffectMode = ShadingEffectMode.One; chart.TitleBox.Position = TitleBoxPosition.None; //圖表背景顏色 chart.ChartArea.Background.Color = ChartAreaBackgroundColor; //1.圖表類型 chart.DefaultSeries.Type = _chartDefaultSeriesType;// SeriesType.Column; //chart.DefaultSeries.Type = SeriesType.Cylinder; //2.圖表類型 //柱狀圖 //chart.Type = ChartType.TreeMap; ////橫向柱狀圖 chart.Type = _chartType;// ChartType.ComboHorizontal ////橫向柱狀圖 //chart.Type =_chartType;// ChartType.Gantt; ////餅狀圖 //chart.Type = ChartType.Pies; //y軸圖表陰影顏色 //chart.YAxis.AlternateGridBackground.Color = Color.FromArgb(255, 250, 250, 250); chart.LegendBox.HeaderLabel = new Label("圖表說(shuō)明", new Font("Microsoft Sans Serif", 10F, FontStyle.Bold, GraphicsUnit.Point, 134)); //chart.LegendBox.HeaderLabel.Font = new Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 134); chart.LegendBox.Label.Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Bold, GraphicsUnit.Point, 134); chart.Palette = new Color[] { Color.FromArgb(0, 156, 255), Color.FromArgb(255, 99, 49), Color.FromArgb(49, 255, 49), Color.FromArgb(255, 255, 0), }; chart.Title = Title; //X軸柱狀圖值字體 chart.XAxis.Label.Text = _xtitle; chart.XAxis.Label.Font = _xAxisLabelFont; //設(shè)置X軸刻度值說(shuō)明字體 chart.XAxis.DefaultTick.Label.Font = _xAxisDefaultTickLabelFont; chart.XAxis.StaticColumnWidth = _staticColumnWidth; //每個(gè)單元格的寬度 //Y軸柱狀圖值字體 chart.YAxis.Label.Text = _ytitle; chart.YAxis.Label.Font = _yAxisLabelFont; //設(shè)置Y軸刻度值說(shuō)明字體 chart.YAxis.DefaultTick.Label.Font = _yAxisDefaultTickLabelFont; //Y軸箭頭標(biāo)示 chart.XAxis.Name = XTitle; if (_chartType == ChartType.ComboHorizontal) { chart.XAxis.TickLabelPadding = 10; chart.XAxis.Line.StartCap = System.Drawing.Drawing2D.LineCap.Square; chart.XAxis.Line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; chart.XAxis.Line.Width = 5;//箭頭寬度 chart.XAxis.Line.Color = Color.Gray; } else { chart.YAxis.TickLabelPadding = 10; chart.YAxis.Line.StartCap = System.Drawing.Drawing2D.LineCap.Square; chart.YAxis.Line.EndCap = System.Drawing.Drawing2D.LineCap.ArrowAnchor; chart.YAxis.Line.Width = 5;//箭頭寬度 chart.YAxis.Line.Color = Color.Gray; //顯示值格式化(小數(shù)新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注