WinFrom Chart柱状图的使用

来源:互联网 发布:淘宝批量发货收费吗 编辑:程序博客网 时间:2024/06/05 19:00

using System.Windows.Forms.DataVisualization.Charting;

 Title title1 = new Title();
            title1.Text = "实时校核总合格率(%)";
            title1.ForeColor = Color.Blue;
            this.chart1.Titles.Add(title1);
            this.chart1.ChartAreas[0].Area3DStyle.Enable3D = true;
            //this.chart1.Series[0]["PointWidth"] = "0.7";

            this.chart1.Series.Clear();
            Series series1 = new Series();
            series1.ChartType = SeriesChartType.Column;
            this.chart1.Series.Add(series1);


            int[] percents = new int[3] { 20, 30, 50 };
            string[] pointsText = new string[3] { "紧急", "严重", "普通" };
            Color[] myColor = new Color[3] { Color.FromArgb(0, 183, 238),
                                              Color.FromArgb(250, 205, 137),
                                                Color.FromArgb(255, 124, 255)};
            DataPoint[] AllPoints = new DataPoint[3];
            for (int i = 0; i < AllPoints.Length; i++)
            {
                AllPoints[i] = new DataPoint(i + 1, percents[i]);
                AllPoints[i].LegendText = "紧急";
                AllPoints[i].Color = myColor[i];
                AllPoints[i].ToolTip = percents[i].ToString() + "%";
                AllPoints[i].Label = percents[i].ToString() + "%";
                AllPoints[i].LabelForeColor = Color.Black;
                this.chart1.Series[0].Points.Add(AllPoints[i]);
            }


            this.chart1.Legends.Clear();
            for (int i = 0; i < 5; i++)
            {
                LegendItem li = new LegendItem();
                li.Name = pointsText[i];
                li.Color = myColor[i];
                li.BorderColor = Color.Transparent;
                this.chart1.Legends[0].CustomItems.Add(li);
            }    
            this.chart1.EndInit();

0 0
原创粉丝点击