4

我有一个 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);
    }

这会产生一个看起来像这样的图表

在此处输入图像描述

但我想单独为列着色,使它们看起来像这样,我还希望列的颜色与其标签相同(所以不是随机的)。

在此处输入图像描述

另外,如何对列进行排序?这样我就可以按照绿色,琥珀色,红色的顺序来拥有它们

4

1 回答 1

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;
            }

        }
于 2013-09-24T13:58:58.230 回答