以下是一些关于柱图的显示代码:
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];
}
效果图: