C# 关于WinForm 中的自带控件 chart1 竖形统计图 使用。

百度查了好久都每找到自己想要的效果C# 关于WinForm 中的自带控件 chart1  竖形统计图 使用。

 

经过一天头痛的摸索终于弄出来了,关键在于Points

/// <summary>
        /// 更新图像图
        /// </summary>
        public void ChartSeriesDataPoint(double dP1, double dP2, double dP3)
        {
            
            chart1.Series["Series1"].Points.Clear();
            chart1.Series.Clear();


            System.Windows.Forms.DataVisualization.Charting.DataPoint dataPoint1 = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0D, dP1);
            dataPoint1.AxisLabel = "自定义名称";
            dataPoint1.BorderWidth = 0;
            dataPoint1.Font = new System.Drawing.Font("隶书", 9.75F, System.Drawing.FontStyle.Bold);
            dataPoint1.IsValueShownAsLabel = true;
            dataPoint1.IsVisibleInLegend = true;
            dataPoint1.LabelBorderWidth = 0;
            dataPoint1.LabelForeColor = System.Drawing.Color.Red;

            System.Windows.Forms.DataVisualization.Charting.DataPoint dataPoint2 = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0D, dP2);
            dataPoint2.AxisLabel = "自定义名称";
            dataPoint2.Font = new System.Drawing.Font("隶书", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            dataPoint2.IsValueShownAsLabel = true;
            dataPoint2.LabelForeColor = System.Drawing.Color.Red;

            System.Windows.Forms.DataVisualization.Charting.DataPoint dataPoint3 = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0D, dP3);
            dataPoint3.AxisLabel = "自定义名称";
            dataPoint3.BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.NotSet;
            dataPoint3.BorderWidth = 0;
            dataPoint3.Font = new System.Drawing.Font("隶书", 9.75F, System.Drawing.FontStyle.Bold);
            dataPoint3.IsValueShownAsLabel = true;
            dataPoint3.LabelForeColor = System.Drawing.Color.Red;

            System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
            series1.ChartArea = "ChartArea1";
            series1.Font = new System.Drawing.Font("微软雅黑", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            series1.IsValueShownAsLabel = true;
            series1.IsXValueIndexed = true;
            series1.LabelBorderWidth = 0;
            series1.MarkerBorderWidth = 2;
            series1.MarkerSize = 0;
            series1.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Star10;
            series1.Name = "Series1";
            series1.Points.Add(dataPoint1);
            series1.Points.Add(dataPoint2);
            series1.Points.Add(dataPoint3);
            this.chart1.Series.Add(series1);
            this.chart1.Update();
            this.chart1.UpdateAnnotations();
        }

 

虽然有点蠢,但是实在能用比一些要收费的还是简单的,微软爹万岁。

欢迎关注LuoCore 微信公众号,大家学习winform控件使用方法

C# 关于WinForm 中的自带控件 chart1 竖形统计图 使用。

上一篇:[C#.NET 拾遗补漏]06:单例模式实佳实践


下一篇:WPF中TabControl控件和ListBox控件的简单应用(MVVM)