亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > C# > 正文

C#中dotnetcharting的用法實例詳解

2020-01-24 02:18:44
字體:
來源:轉載
供稿:網友

本文以實例形式詳細講述了dotnetcharting控件的用法。分享給大家供大家參考。具體用法分析如下:

dotnetcharting 是一個很好用的圖表控件,能畫出很漂亮的報表,一般常用到的主要有柱狀圖、餅圖、折線圖三種。
dotnetcharting 有web版、winform版多個版本可供使用,官方網址:http://www.dotnetcharting.com/ ,官網有很多示例(http://www.dotnetcharting.com/gallery/),而且有winform安裝版示例和代碼,如下圖。
dotnetcharting 有網上破解版的,去百度或谷歌一搜一堆。
說下個人感受,該控件是國外開發的,雖然說這個控件挺好用的,但是感覺這個控件應該在有xp系統的時候就應該有了吧?是國外剩下的技術,咱們一直在用別人不用的技術,捧為珍寶。
有些技術有些人,有些本事就開始自大起來,小有成就的那點技術還藏著掖著。 呵呵。。。

 

接下來上干貨,前兩天剛使用dotnetcharting 做了個統計報表,代碼如下:
 

復制代碼 代碼如下:
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
    // 時間:2014/10/9 11:49:48
    // </summary>
    public class ShowData
    {
        #region 屬性
        private string _phaysicalimagepath;//圖片存放路徑
        private string _xtitle;//圖片x座標名稱
        private string _ytitle;//圖片y座標名稱
        private string _seriesname;//圖例名稱
        private int _picwidth;//圖片寬度
        private int _pichight;//圖片高度
        private DataTable _dt;//圖片數據源
        private DataSet _ds;//圖片數據源
 
        private Color _titleBoxColor;//圖片標題背景色
        private Font _titleBoxFont;//圖片標題字體
        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;//設置柱狀圖每個單元格的寬度
        private int _numberPercision;//設置數值小數點
 
        /// <summary>
        /// 圖片存放路徑
        /// </summary>
        public string PhaysicalImagePath
        {
            set { _phaysicalimagepath = value; }
            get { return _phaysicalimagepath; }
        }
 
        /// <summary>
        /// 圖片標題
        /// </summary>
        public string Title { get; set; }
 
        /// <summary>
        /// 圖片標題
        /// </summary>
        public string XTitle
        {
            set { _xtitle = value; }
            get { return _xtitle; }
        }
        /// <summary>
        /// 圖片標題
        /// </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 DataTable DataSource
        {
            set { _dt = value; }
            get { return _dt; }
        }
        /// <summary>
        /// 圖片數據源
        /// </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 構造函數
        public ShowData()
        {
            //
            // TODO: 在此處添加構造函數邏輯
            //
            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
            {
                //清空圖片
                chart.SeriesCollection.Clear();
                //標題框設置
                //標題的顏色
                chart.TitleBox.Label.Color = _titleBoxColor;
                //標題字體設置
                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("圖表說明", 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;
                //設置X軸刻度值說明字體
                chart.XAxis.DefaultTick.Label.Font = _xAxisDefaultTickLabelFont;
 
                chart.XAxis.StaticColumnWidth = _staticColumnWidth; //每個單元格的寬度
 
 
                //Y軸柱狀圖值字體
                chart.YAxis.Label.Text = _ytitle;
                chart.YAxis.Label.Font = _yAxisLabelFont;
                //設置Y軸刻度值說明字體
                chart.YAxis.DefaultTick.Label.Font = _yAxisDefaultTickLabelFont;
 
                //Y軸箭頭標示
                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;
                    //顯示值格式化(小數點顯示幾位)
                    chart.YAxis.NumberPercision = _numberPercision;
                }
 
                //圖片存放路徑
                chart.TempDirectory = System.Environment.CurrentDirectory + "http://" + _phaysicalimagepath;
                //圖表寬度
                chart.Width = _picwidth;
                //圖表高度
                chart.Height = _pichight;
                chart.Series.Name = _seriesname;
                //單一圖形
                //chart.Series.Data = _dt;
                //chart.SeriesCollection.Add();
 
                //圖例在標題行顯示,但是沒有合計信息
                //chart.TitleBox.Position = TitleBoxPosition.FullWithLegend;
                //chart.TitleBox.Label.Alignment = StringAlignment.Center;
                //chart.LegendBox.Position = LegendBoxPosition.None; //不顯示圖例,指不在右側顯示,對上面一行的屬性設置并沒有影響
 
                chart.DefaultSeries.DefaultElement.ShowValue = true;
                chart.ShadingEffect = true;
                chart.Use3D = false;
                chart.Series.DefaultElement.ShowValue = true;
                chart.SeriesCollection.Add(GetArrayData());
 
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog(ex.ToString(), ex);
            }
        }
 
        /// <summary>
        /// 柱形圖
        /// </summary>
        /// <returns></returns>
        public void CreateColumn(Chart chart, List<int> list)
        {
            try
            {
                chart.SeriesCollection.Clear();
                //標題框設置
                //標題的顏色
                chart.TitleBox.Label.Color = _titleBoxColor;
                //標題字體設置
                chart.TitleBox.Label.Font = _titleBoxFont;
 
                //控制柱狀圖顏色
                chart.ShadingEffectMode = ShadingEffectMode.Five;
                //圖表背景顏色
                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("圖表說明", 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;
                //設置X軸刻度值說明字體
                chart.XAxis.DefaultTick.Label.Font = _xAxisDefaultTickLabelFont;
 
                chart.XAxis.StaticColumnWidth = _staticColumnWidth; //每個單元格的寬度
 
 
                //Y軸柱狀圖值字體
                chart.YAxis.Label.Text = _ytitle;
                chart.YAxis.Label.Font = _yAxisLabelFont;
                //設置Y軸刻度值說明字體
                chart.YAxis.DefaultTick.Label.Font = _yAxisDefaultTickLabelFont;
 
                //Y軸箭頭標示
                chart.XAxis.Name = XTitle;
                if (_chartType == dotnetCHARTING.WinForms.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;
                    //顯示值格式化(小數點顯示幾位)
                    chart.YAxis.NumberPercision = _numberPercision;
                }
 
                //圖片存放路徑
                chart.TempDirectory = System.Environment.CurrentDirectory + "http://" + _phaysicalimagepath;
                //圖表寬度
                chart.Width = _picwidth;
                //圖表高度
                chart.Height = _pichight;
                chart.Series.Name = _seriesname;
                //單一圖形
                //chart.Series.Data = _dt;
                //chart.SeriesCollection.Add();
 
                //圖例在標題行顯示,但是沒有合計信息
                //chart.TitleBox.Position = TitleBoxPosition.FullWithLegend;
                //chart.TitleBox.Label.Alignment = StringAlignment.Center;
                //chart.LegendBox.Position = LegendBoxPosition.None; //不顯示圖例,指不在右側顯示,對上面一行的屬性設置并沒有影響
 
                chart.DefaultSeries.DefaultElement.ShowValue = true;
                chart.ShadingEffect = true;
                chart.Use3D = false;
                chart.Series.DefaultElement.ShowValue = true;
 
 
                chart.SeriesCollection.Add(GetArrayData(list));
 
            }
            catch (Exception ex)
            {
 
                LogHelper.WriteErrorLog(ex.ToString(), ex);
            }
        }
 
 
        ///// <summary>
        ///// 柱形圖,單一圖片
        ///// </summary>
        ///// <returns></returns>
        //public void CreateColumn(Chart chart1)
        //{
        // Chart1.Title = _title;
        // Chart1.XAxis.Label.Text = _xtitle;
        // Chart1.YAxis.Label.Text = _ytitle;
        // Chart1.TempDirectory = PhaysicalImagePath;
        // Chart1.Width = _picwidth;
        // Chart1.Height = _pichight;
        // Chart1.Type = ChartType.Combo;
 
        // Chart1.Series.Type = SeriesType.Cylinder;
        // Chart1.Series.Name = _seriesname;
        // Chart1.Series.Data = _dt;
        // Chart1.SeriesCollection.Add();
        // Chart1.DefaultSeries.DefaultElement.ShowValue = true;
        // Chart1.ShadingEffect = true;
        // Chart1.Use3D = false;
        // Chart1.Series.DefaultElement.ShowValue = true;
        //}
 
        #endregion
 
        #region 輸出餅圖
        /// <summary>
        /// 餅圖
        /// </summary>
        /// <returns></returns>
        public void CreatePie(Chart chart)
        {
            try
            {
 
                chart.SeriesCollection.Clear();
                //控制餅圖顏色
                chart.ShadingEffectMode = ShadingEffectMode.Two;
 
                chart.TitleBox.Position = TitleBoxPosition.None;
                chart.Title = Title;
                //標題的顏色
                chart.TitleBox.Label.Color = _titleBoxColor;
                //標題字體設置
                chart.TitleBox.Label.Font = _titleBoxFont;
 
                //圖表說明
                chart.LegendBox.HeaderLabel = new dotnetCHARTING.WinForms.Label("圖表說明", new Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.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, System.Drawing.FontStyle.Bold, System.Drawing.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;
                //設置X軸刻度值說明字體
                chart.XAxis.DefaultTick.Label.Font = _xAxisDefaultTickLabelFont;
                chart.XAxis.Label.Text = _xtitle;
                chart.YAxis.Label.Text = _ytitle;
                chart.TempDirectory = _phaysicalimagepath;
                chart.Width = _picwidth;
                chart.Height = _pichight;
                chart.Type = ChartType.Pie;
                chart.Series.Type = SeriesType.Cylinder;
                chart.Series.Name = _seriesname;
                chart.YAxis.NumberPercision = _numberPercision;
 
                chart.ShadingEffect = true;
                chart.Use3D = false;
                chart.DefaultSeries.DefaultElement.Transparency = 20;//線條透明度
                chart.DefaultSeries.DefaultElement.ShowValue = true;
                chart.PieLabelMode = dotnetCHARTING.WinForms.PieLabelMode.Outside;
                chart.SeriesCollection.Add(GetPieArrayData());
                chart.Series.DefaultElement.ShowValue = true;
 
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog(ex.ToString(), ex);
            }
        }
 
        #region 輸出曲線圖
        /// <summary>
        /// 曲線圖,昨日今日對比
        /// </summary>
        /// <returns></returns>
        public void CreateLine(Chart chart)
        {
            try
            {
                chart.SeriesCollection.Clear();
 
                chart.TitleBox.Position = TitleBoxPosition.None;
                //標題的顏色
                chart.TitleBox.Label.Color = _titleBoxColor;
                //標題字體設置
                chart.TitleBox.Label.Font = _titleBoxFont;
                //圖表背景顏色
                chart.ChartArea.Background.Color = ChartAreaBackgroundColor;
 
                //X軸柱狀圖值字體
                chart.XAxis.Label.Font = _xAxisLabelFont;
                //設置X軸刻度值說明字體
                chart.XAxis.DefaultTick.Label.Font = _xAxisDefaultTickLabelFont;
 
                //Y軸柱狀圖值字體
                chart.YAxis.Label.Font = _yAxisLabelFont;
                //設置Y軸刻度值說明字體
                chart.YAxis.DefaultTick.Label.Font = _yAxisDefaultTickLabelFont;
 
                //Y軸箭頭標示
                chart.YAxis.TickLabelPadding = 0;
                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;
 
                chart.Title = Title;
                chart.XAxis.Label.Text = _xtitle;
                chart.YAxis.Label.Text = _ytitle;
                chart.TempDirectory = _phaysicalimagepath;
                // Set the size
                chart.Width = _picwidth;
                chart.Height = _pichight;
                // Set the temp directory
                chart.TempDirectory = "temp";
                // Debug mode. ( Will show generated errors if any )
                chart.Debug = true;
                chart.Type = ChartType.Combo;
                chart.DefaultSeries.Type = SeriesType.Line;
                //chart.Series.Type = SeriesType.Line;
                chart.Series.Name = _seriesname;
                chart.DefaultSeries.DefaultElement.ShowValue = false;
                chart.ShadingEffect = true;
                chart.Use3D = false;
                chart.Series.DefaultElement.ShowValue = true;
                chart.DefaultSeries.DefaultElement.Transparency = 20;//線條透明度
                chart.DateGrouping = TimeInterval.Day;
                ////顯示值格式化(小數點顯示幾位)
                chart.YAxis.NumberPercision = _numberPercision;
 
                chart.OverlapFooter = false;
 
                SeriesCollection mySC = GetRandomData();
                mySC[0].DefaultElement.Color = Color.FromArgb(255, 99, 49);
                mySC[1].DefaultElement.Color = Color.FromArgb(0, 156, 255);
 
                // Add the random data.
                chart.SeriesCollection.Add(mySC);
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog(ex.ToString(), ex);
            }
        }
        #endregion
 
        /// <summary>
        /// 曲線圖
        /// </summary>
        /// <returns></returns>
        SeriesCollection GetRandomData()
        {
            SeriesCollection sc = new SeriesCollection();
            try
            {
                DataTable dt = _dt;
 
                var s = new Series();
                var s2 = new Series();
 
                switch (SeriesTypeE)
                {
                    case ModelConseme.DateChartEnum.DayChart:
                        for (int i = 0; i < 24; i++)
                        {
                            s.Name = "今天";
                            s2.Name = "昨天";
                            Element e = new Element();
                            // 每元素的名稱
                            e.Name = (i).ToString();
                            // 每元素的大小數值
                            e.YValue = 0;
 
                            Element e2 = new Element();
                            // 每元素的名稱
                            e2.Name = (i).ToString();
                            // 每元素的大小數值
                            e2.YValue = 0;
 
                            s.Elements.Add(e);
                            s2.Elements.Add(e2);
                            sc.Add(s);
                            sc.Add(s2);
                        }
 
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            string sodayHH = dt.Rows[i][1].ToString();
                            string today = dt.Rows[i][1].ToString().Substring(0, 10);
                            int HH = Convert.ToInt32(sodayHH.Substring(11));
                            if (DateTime.Now.ToString("yyyy-MM-dd").Equals(today))
                            {
                                sc[0].Elements[HH].YValue = Convert.ToDouble(dt.Rows[i][2].ToString());
                            }
                            else
                            {
                                sc[1].Elements[HH].YValue = Convert.ToDouble(dt.Rows[i][2].ToString());
                            }
                        }
                        break;
                    case ModelConseme.DateChartEnum.MonthChart:
                        for (int i = 1; i < 32; i++)
                        {
                            s.Name = "本月";
                            s2.Name = "上月";
                            var e = new Element();
                            // 每元素的名稱
                            e.Name = (i).ToString();
                            // 每元素的大小數值
                            e.YValue = 0;
 
                            var e2 = new Element();
                            // 每元素的名稱
                            e2.Name = (i).ToString();
                            // 每元素的大小數值
                            e2.YValue = 0;
 
                            s.Elements.Add(e);
                            s2.Elements.Add(e2);
                            sc.Add(s);
                            sc.Add(s2);
                        }
 
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            string sodayHH = dt.Rows[i][1].ToString();
                            string month = dt.Rows[i][1].ToString().Substring(0, 7);
                            int ovaule = Convert.ToInt32(sodayHH.Substring(8));
                            if (DateTime.Now.ToString("yyyy-MM").Equals(month))
                            {
                                sc[0].Elements[ovaule - 1].YValue = Convert.ToDouble(dt.Rows[i][2].ToString());
                            }
                            else
                            {
                                sc[1].Elements[ovaule - 1].YValue = Convert.ToDouble(dt.Rows[i][2].ToString());
                            }
                        }
                        break;
                    case ModelConseme.DateChartEnum.YearChart:
                        for (int i = 1; i < 13; i++)
                        {
                            s.Name = "本年";
                            s2.Name = "去年";
                            Element e = new Element();
                            // 每元素的名稱
                            e.Name = (i).ToString();
                            // 每元素的大小數值
                            e.YValue = 0;
 
                            Element e2 = new Element();
                            // 每元素的名稱
                            e2.Name = (i).ToString();
                            // 每元素的大小數值
                            e2.YValue = 0;
 
                            s.Elements.Add(e);
                            s2.Elements.Add(e2);
                            sc.Add(s);
                            sc.Add(s2);
                        }
 
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            string sodayHH = dt.Rows[i][1].ToString();
                            string year = dt.Rows[i][1].ToString().Substring(0, 4);
                            int ovaule = sodayHH.Contains("-") ? Convert.ToInt32(sodayHH.Substring(5)) : Convert.ToInt32(sodayHH.Substring(4));
                            if (DateTime.Now.ToString("yyyy").Equals(year))
                            {
                                sc[0].Elements[ovaule - 1].YValue = Convert.ToDouble(dt.Rows[i][2].ToString());
                            }
                            else
                            {
                                sc[1].Elements[ovaule - 1].YValue = Convert.ToDouble(dt.Rows[i][2].ToString());
                            }
                        }
                        break;
                }
 
                //SC[0].PaletteName = Palette.None;//.Color = Color.FromArgb(49,255,49);
 
                return sc;
            }
            catch (Exception ex)
            {
 
                LogHelper.WriteErrorLog(ex.ToString(), ex);
                return sc;
            }
        }
 
 
        /// <summary>
        /// 餅圖
        /// </summary>
        /// <returns></returns>
        private SeriesCollection GetPieArrayData()
        {
            SeriesCollection sc = new SeriesCollection();
            try
            {
                DataTable dt = _dt;
 
 
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Series s = new Series();
                    s.Name = dt.Rows[i][1].ToString();
                    Element e = new Element();
 
                    // 每元素的名稱
                    e.Name = dt.Rows[i][1].ToString();
                    //設置柱狀圖值的字體
                    e.SmartLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 134);
                    //e.SmartLabel.DynamicDisplay = true;
                    //e.SmartLabel.AutoWrap = true;
                    // 每元素的大小數值
                    e.YValue = Convert.ToDouble(dt.Rows[i][2].ToString());
                    //s.PaletteName = Palette.Three;
                    //s.DefaultElement.Color = Color.FromArgb(49, 255, 49);
                    s.Elements.Add(e);
                    sc.Add(s);
                }
 
                //SC[0].PaletteName = Palette.Poppies;//.Color = Color.FromArgb(49,255,49);
 
                //SC[0].DefaultElement.Color = Color.FromArgb(49, 255, 49);
                //SC[0].DefaultElement.Color = Color.FromArgb(49, 255, 49);
                //SC[1].DefaultElement.Color = Color.FromArgb(255, 255, 0);
                //SC[2].DefaultElement.Color = Color.FromArgb(255, 99, 49);
                //SC[3].DefaultElement.Color = Color.FromArgb(0, 156, 255);
                return sc;
 
            }
            catch (Exception ex)
            {
 
                LogHelper.WriteErrorLog(ex.ToString(), ex);
                return sc;
            }
        }
 
        /// <summary>
        /// 柱狀圖
        /// </summary>
        /// <returns></returns>
        private SeriesCollection GetArrayData()
        {
            SeriesCollection sc = new SeriesCollection();
            try
            {
                DataTable dt = _dt;
                Series s = new Series();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    s.Name = dt.Rows[i][1].ToString();
                    if (s.Name == "") continue;
                    var e = new Element();
 
                    // 每元素的名稱
                    e.Name = dt.Rows[i][1].ToString();
                    //設置柱狀圖值的字體
                    e.SmartLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 134);
                    //e.SmartLabel.DynamicDisplay = true;
                    //e.SmartLabel.AutoWrap = true;
                    // 每元素的大小數值
                    e.YValue = Convert.ToDouble(dt.Rows[i][2].ToString());
                    //調整柱子顏色
                    //s.PaletteName = Palette.Three;
                    s.Palette = new Color[] { Color.FromArgb(0, 156, 255), Color.FromArgb(255, 99, 49), Color.FromArgb(49, 255, 49), Color.FromArgb(255, 255, 0), };
 
                    s.Elements.Add(e);
                }
                sc.Add(s);
                return sc;
 
            }
            catch (Exception ex)
            {
 
                LogHelper.WriteErrorLog(ex.ToString(), ex);
                return sc;
            }
        }
 
 
        /// <summary>
        /// 柱狀圖
        /// </summary>
        /// <returns></returns>
        private SeriesCollection GetArrayData(List<int> list)
        {
            SeriesCollection sc = new SeriesCollection();
            try
            {
 
                DataTable dt = _ds.Tables[list[0]];
                DataTable dt2 = _ds.Tables[list[1]];
 
                Dictionary<string, string> oilDicT = new Dictionary<string, string>();
                Dictionary<string, string> oilDicY = new Dictionary<string, string>();
 
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    oilDicT.Add(dt.Rows[i][1].ToString(), dt.Rows[i][2].ToString());
                }
                for (int i = 0; i < dt2.Rows.Count; i++)
                {
                    oilDicY.Add(dt2.Rows[i][1].ToString(), dt2.Rows[i][2].ToString());
                }
 
                foreach (KeyValuePair<string, string> keyValue in oilDicT)
                {
                    if (!oilDicY.ContainsKey(keyValue.Key))
                    {
                        oilDicY.Add(keyValue.Key, "0");
                    }
                }
 
                foreach (KeyValuePair<string, string> keyValue in oilDicY)
                {
                    if (!oilDicT.ContainsKey(keyValue.Key))
                    {
                        oilDicT.Add(keyValue.Key, "0");
                    }
                }
                var oiList = new List<Dictionary<string, string>> { oilDicT, oilDicY };
 
                for (int a = 0; a < oiList.Count; a++)
                {
                    var dicN = oiList[a];
                    Series s = new Series();
                    switch (SeriesTypeE)
                    {
                        case ModelConseme.DateChartEnum.DayChart:
                            s.Name = a == 0 ? "今天" : "昨天";
                            break;
                        case ModelConseme.DateChartEnum.MonthChart:
                            s.Name = a == 0 ? "本月" : "上月";
                            break;
                        case ModelConseme.DateChartEnum.YearChart:
                            s.Name = a == 0 ? "今年" : "去年";
                            break;
                    }
 
 
                    foreach (KeyValuePair<string, string> keyValue in dicN)
                    {
                        Element e = new Element();
 
                        // 每元素的名稱
                        e.Name = keyValue.Key;
                        //設置柱狀圖值的字體
                        e.SmartLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F,
                            System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 134);
                        //e.SmartLabel.DynamicDisplay = true;
                        //e.SmartLabel.AutoWrap = true;
                        // 每元素的大小數值
                        e.YValue = Convert.ToDouble(keyValue.Value);
                        //s.PaletteName = Palette.Poppies;
                        //s.DefaultElement.Color = Color.FromArgb(49, 255, 49);
                        s.Elements.Add(e);
                    }
                    sc.Add(s);
                }
                return sc;
 
            }
            catch (Exception ex)
            {
 
                LogHelper.WriteErrorLog(ex.ToString(), ex);
                return sc;
            }
        }
 
 
        /// <summary>
        /// 柱狀圖2
        /// </summary>
        /// <returns></returns>
        private SeriesCollection GetArrayData2()
        {
            SeriesCollection sc = new SeriesCollection();
            try
            {
                DataTable dt = _dt;
 
                for (int a = 0; a < 2; a++)
                {
                    Series s = new Series();
                    s.Name = (a == 0 ? "今天" : "昨天");
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        Element e = new Element();
 
                        // 每元素的名稱
                        e.Name = dt.Rows[i][1].ToString();
                        //設置柱狀圖值的字體
                        e.SmartLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 134);
                        //e.SmartLabel.DynamicDisplay = true;
                        //e.SmartLabel.AutoWrap = true;
                        // 每元素的大小數值
                        e.YValue = Convert.ToDouble(dt.Rows[i][2].ToString());
                        s.PaletteName = Palette.Poppies;
                        //s.DefaultElement.Color = Color.FromArgb(49, 255, 49);
                        s.Elements.Add(e);
                    }
 
                    sc.Add(s);
                }
                return sc;
 
            }
            catch (Exception ex)
            {
 
                LogHelper.WriteErrorLog(ex.ToString(), ex);
                return sc;
            }
        }
        #endregion
    }
}

 
調用方法:
復制代碼 代碼如下:
ShowData show = new ShowData();
//show.PicHight = 494;
//show.PicWidth = 1336;
show.SeriesName = "具體詳情";
show.PhaysicalImagePath = "ChartImages";
show.TitleBoxColor = Color.Blue;
show.TitleBoxFont = new Font("Arial", 10, FontStyle.Bold);
show.ChartAreaBackgroundColor = Color.Honeydew;
show.XAxisLabelFont = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
show.YAxisLabelFont = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
show.XAxisDefaultTickLabelFont = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
show.YAxisDefaultTickLabelFont = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
show.ChartDefaultSeriesType = SeriesType.Column;
show.DataSetSource = dsSet;
show.SeriesTypeE = modelConseme.DateChart;

//餅圖
show.YTitle = "油量(升)";
//show.Title = strOils + strDate + strConsume + "銷售油量報表統計圖"; 
show.XTitle = "";
show.DataSource = dsSet.Tables[0];
show.CreatePie(this.chart1);

//柱狀圖(兩條柱子對比)
 show.YTitle = "油量(升)";
label2.Text = strDate + strOils + strConsume + @"油品對比圖";
show.XTitle = "油品";
//show.DataSource = dsSet.Tables[2];
show.StaticColumnWidth = 0;
show.CreateColumn(chart2, new List<int>()
{
0,
1
});

//曲線圖
show.YTitle = "油量(升)";
label5.Text = strDate + strOils + strConsume + @"油量環比圖";
show.XTitle = "時間";
show.DataSource = dsSet.Tables[4];
show.CreateLine(this.chart5);

//單個柱子
var show = new ShowData
{
    Title = "近30天加油會員統計",
    XTitle = "人數",
    YTitle = "會員分類",
    SeriesName = "具體詳情",
    PhaysicalImagePath = "ChartImages",
    DataSource = dsSet.Tables[0],
    TitleBoxColor = Color.Blue,
    TitleBoxFont = new Font("Arial", 10, FontStyle.Bold),
    ChartAreaBackgroundColor = Color.Honeydew,
    XAxisLabelFont = new Font("Microsoft Sans Serif", 10F, FontStyle.Bold, GraphicsUnit.Point, 134),
    YAxisLabelFont = new Font("Microsoft Sans Serif", 10F, FontStyle.Bold, GraphicsUnit.Point, 134),
    XAxisDefaultTickLabelFont =
 new Font("Microsoft Sans Serif", 10F, FontStyle.Bold, GraphicsUnit.Point, 134),
    YAxisDefaultTickLabelFont =
 new Font("Microsoft Sans Serif", 10F, FontStyle.Bold, GraphicsUnit.Point, 134),
    ChartDefaultSeriesType = SeriesType.Column,
    ChartType = ChartType.ComboHorizontal,
    StaticColumnWidth = 80
};
show.CreateColumn(chart1);

show.NumberPercision = 0;
show.CreatePie(chart2);

運行效果圖如下:

 

希望本文所述對大家的C#程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
不卡伊人av在线播放| 成人性生交大片免费看小说| 国产日韩在线精品av| 日韩精品在线看| 色偷偷综合社区| 精品成人久久av| 国产精品白嫩初高中害羞小美女| 亚洲视频免费一区| 亚洲欧美视频在线| 国产精品免费在线免费| 国产在线视频一区| 精品国产成人在线| 成人欧美一区二区三区在线湿哒哒| 亚洲男人的天堂在线| 国产精品久久久久77777| 日韩电影在线观看永久视频免费网站| 久久人人爽人人| 欧美日韩免费在线观看| 欧美黑人国产人伦爽爽爽| 国产精品日韩欧美综合| 国产精品福利在线观看网址| 日本高清视频一区| 国产精品久久久久av| 亚洲色无码播放| 91在线免费视频| 最近2019年手机中文字幕| 久久亚洲一区二区三区四区五区高| 国产精品久久久久av| 精品国产999| 91麻豆桃色免费看| 国产成人福利夜色影视| 国产精品中文字幕久久久| 国产综合色香蕉精品| 国产精品黄视频| 国产精品国产三级国产aⅴ浪潮| 亚洲欧美色图片| 久久久久国产精品一区| 中文字幕最新精品| 88国产精品欧美一区二区三区| 久久久亚洲国产天美传媒修理工| 色悠久久久久综合先锋影音下载| 日韩欧美精品免费在线| 一区二区三区视频免费在线观看| 亚洲美女av电影| 亚洲国产一区二区三区四区| 亚洲高清福利视频| 久久精品国产99国产精品澳门| 亚洲精品久久久久国产| 欧美国产激情18| 麻豆一区二区在线观看| 亚洲欧美在线磁力| 国产成人精品视频在线| 欧美国产日韩一区二区三区| 日本人成精品视频在线| 精品国产欧美一区二区三区成人| 国产精品美女视频网站| 国模吧一区二区| 亚洲成色www8888| 91在线视频九色| 国产精品久久久久aaaa九色| 亚洲色图第一页| 亚洲精选中文字幕| 日本亚洲欧洲色α| 亚洲人精选亚洲人成在线| 91av网站在线播放| 在线视频日韩精品| 国产成人精品最新| 亚洲激情视频网站| 欧美日韩另类视频| 亚洲综合色激情五月| 日韩在线免费高清视频| 成人国产在线视频| 亚洲色图校园春色| 欧美日韩免费在线观看| 亚洲男人av在线| 亚洲国产精彩中文乱码av| 国产精品aaaa| 国产精品69久久| 亚洲国产黄色片| 色噜噜国产精品视频一区二区| 亚洲已满18点击进入在线看片| 欧美丰满少妇xxxxx做受| 久久久久免费视频| 性亚洲最疯狂xxxx高清| 国产精品视频26uuu| 欧美色videos| 亚洲成人精品久久| 俺去了亚洲欧美日韩| 亚洲在线观看视频网站| 久久天天躁狠狠躁老女人| 色综合久久中文字幕综合网小说| 一本色道久久88亚洲综合88| 国产精品日韩专区| 亚洲色图狂野欧美| 国产精品一区二区久久久久| 国产亚洲人成a一在线v站| 欧美在线观看视频| 精品福利在线视频| 91av成人在线| 欧美性在线观看| 亚洲欧美日韩在线一区| 亚洲国产欧美一区| 亚洲系列中文字幕| 欧美激情视频一区二区| 亚洲欧美日韩一区二区三区在线| 久久精品视频在线观看| xxxx欧美18另类的高清| 久久久久久久网站| 国产精品一区二区久久久久| 综合136福利视频在线| 久久91亚洲人成电影网站| 狠狠色噜噜狠狠狠狠97| 国产精品视频在线播放| 日韩在线观看高清| 国产精品自拍偷拍视频| 另类少妇人与禽zozz0性伦| 亚洲天堂免费在线| 午夜免费久久久久| 国产欧美精品在线播放| 最近2019中文字幕在线高清| 97精品欧美一区二区三区| 精品国产福利视频| 亚洲欧美一区二区激情| 欧美国产日本高清在线| 久久亚洲影音av资源网| 日韩精品视频在线观看网址| 久久久久中文字幕2018| 国产精品久久77777| 亚洲**2019国产| 精品福利在线视频| 中日韩午夜理伦电影免费| 亚洲性69xxxbbb| 亚洲日韩中文字幕| 国产不卡av在线免费观看| 日韩美女在线播放| 欧美电影在线观看网站| 大荫蒂欧美视频另类xxxx| 亚洲精品久久久久久下一站| 国产亚洲人成a一在线v站| 精品欧美aⅴ在线网站| 国产精品自产拍高潮在线观看| 国产盗摄xxxx视频xxx69| 久久亚洲精品中文字幕冲田杏梨| 久久99精品久久久久久青青91| 国产精品日日摸夜夜添夜夜av| 国产有码一区二区| 久久久久久尹人网香蕉| 亚洲xxxx18| 精品欧美国产一区二区三区| 亚洲xxxxx性| 欧美综合一区第一页| 国产在线精品播放| 欧美影院成年免费版| 亚洲第一男人av| 在线日韩精品视频| 亚洲黄色在线观看| 久久久久国产一区二区三区| 欧美亚洲一区在线| 欧美黑人一级爽快片淫片高清| 欧美国产高跟鞋裸体秀xxxhd| 最新69国产成人精品视频免费| 久久99久国产精品黄毛片入口| 日韩av观看网址| 久久免费精品日本久久中文字幕|