Chart 圖表 柱圖

以下是一些關於柱圖的顯示代碼:

MyChart.Series.Clear();
                    //Chart
                    var series = new Series();

                    series.Label = "#VAL";
                    series.LegendText = "金額(單位:元)";
                    series.Color = Color.Green;
                    series.YValueMembers = "ProductMoney";
                    series.XValueMember = "ProductName";

                    MyChart.Series.Add(series);


                    //標題
                    var title = new Title();
                    title.Text = "銷售概況";
                    title.Alignment = ContentAlignment.MiddleCenter;
                    title.Font = new System.Drawing.Font("Trebuchet MS", 14F, FontStyle.Bold);
                    MyChart.Titles.Add(title);

                    //邊框樣式設置 ChartArea1
                    MyChart.ChartAreas["ChartArea1"].BorderColor = Color.Black;
                    MyChart.ChartAreas["ChartArea1"].BorderWidth = 1;
                    MyChart.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;
                    MyChart.ChartAreas[0].AxisX.Interval = 1;
                    MyChart.ChartAreas[0].AxisX.IntervalOffset = 1;

                    MyChart.ChartAreas[0].AxisX.LabelStyle.IsStaggered = true;
                    MyChart.ChartAreas[0].AxisX.LabelStyle.Angle = 89;
                    MyChart.ChartAreas[0].AxisX.LabelStyle.Font = new System.Drawing.Font("微軟雅黑", 9F);
                    //MyChart.ChartAreas[0].AxisX.LabelStyle.

                    //背景色
                    //MyChart.Legends["Legends1"]. = "金額";
                    MyChart.Legends["Legends1"].BackColor = Color.FromArgb(235, 235, 235);


                    //斜線背景
                    MyChart.Legends["Legends1"].BackHatchStyle = ChartHatchStyle.DarkDownwardDiagonal;
                    MyChart.Legends["Legends1"].BorderWidth = 1;
                    MyChart.Legends["Legends1"].BorderColor = Color.FromArgb(200, 200, 200);

                    //設置圖例說明
                    MyChart.ChartAreas["ChartArea1"].AxisY.TitleFont = new Font("微軟雅黑", float.Parse("8"), FontStyle.Regular);
                    MyChart.ChartAreas["ChartArea1"].AxisY.TitleForeColor = Color.FromName("Black");
                    MyChart.ChartAreas["ChartArea1"].AxisY.Title = "銷售額";
                    MyChart.ChartAreas["ChartArea1"].AxisX.TitleFont = new Font("微軟雅黑", float.Parse("8"), FontStyle.Regular);
                    MyChart.ChartAreas["ChartArea1"].AxisX.TitleForeColor = Color.FromName("Black");
                    MyChart.ChartAreas["ChartArea1"].AxisX.Title = "產品名稱";



                    MyChart.DataSource = list;
                    MyChart.DataBind();

                    //初始化柱子顏色 
                    Color[] colorValues = new Color[] {Color.IndianRed, Color.DarkTurquoise, Color.Red, Color.SlateGray, Color.Gold, Color.Green, Color.Indigo, Color.MediumOrchid};

                    for (int i = 0; i < MyChart.Series[0].Points.Count; i++)
                    {
                        MyChart.Series[0].Points[i].Color = colorValues[i];
                    }

效果圖:




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章