我有一个ascx页面,代码背后的代码如下所示
private void CreateProjectsByRAG()
{
foreach (ProjectStatistic PR in repository.GetProjectByRAG())
{
ProjectsByProjectTypePieChart.Series["series"].Points.AddXY(PR.Name, PR.Value);
}
ProjectsByProjectTypePieChart.Titles["Title1"].Text = "Projects by RAG Status";
ProjectsByProjectTypePieChart.Series["series"].ChartType = SeriesChartType.Column;// Set the Pie width
ProjectsByProjectTypePieChart.Series["series"].Color = System.Drawing.Color.FromArgb(255, 0, 0);
}
生成一个看起来像这样的图表
但我想单独为列着色,使它们看起来像这样,我也希望列与其标签具有相同的颜色(因此不是随机的)。
另外,如何订购列?所以我可以按照Green,Amber,Red的顺序排列它们
答案 0 :(得分:5)
代码是
foreach (ProjectStatistic PR in repository.GetProjectByRAG())
{
int index = ProjectsByProjectTypePieChart.Series["series"].Points.AddXY(PR.Name, PR.Value);
if (PR.Name == "Green")
{
ProjectsByProjectTypePieChart.Series["series"].Points[index].Color = System.Drawing.Color.Green;
}
if (PR.Name == "Amber")
{
ProjectsByProjectTypePieChart.Series["series"].Points[index].Color = System.Drawing.Color.Yellow;
}
if (PR.Name == "Red")
{
ProjectsByProjectTypePieChart.Series["series"].Points[index].Color = System.Drawing.Color.Red;
}
}