我正在尝试使用从C#.NET数据库中提取的数据创建一个简单的饼图。我已经使用以下代码:
它展示了正确数值的饼状图。但是当我试图为香蕉(绿色)、芒果(红色)和苹果(灰色)指定特定颜色时,它显示出错信息:“索引超出范围,必须是非负数……”。有人能给我一些提示吗?
string[] xAxis = { "Banana", "Mango", "Apple" };
double BananaPercentage= 40;
double MangoPercentage= 30;
double ApplePercentage = 30;
double[] Percentage = { BananaPercentage, MangoPercentage, ApplePercentage };
Color[] PieColors = { Color.Green, Color.Red, Color.Gray };
chart1.Series[0].Label = "#PERCENT";
chart1.Series[0].LegendText = "#AXISLABEL";
//chart1.Series[0].Points[0].Color = PieColors[0];
chart1.Series[0].Points.DataBindXY(xAxis, Percentage);
它展示了正确数值的饼状图。但是当我试图为香蕉(绿色)、芒果(红色)和苹果(灰色)指定特定颜色时,它显示出错信息:“索引超出范围,必须是非负数……”。有人能给我一些提示吗?
chart1.Series[0].Points[0].Color = PieColors[0];
之前尝试使用chart1.Series[0].Points.DataBindXY(xAxis, Percentage);
。 - AWinkle