How to change the color of individual columns in a chart control?


I have an ascx page and the code behind the code looks like this

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

Which produces a chart that looks like this

enter image description here

But I want to color the columns individually so they look like this, I also want the columns to have the same color as their label (so not random).

enter image description here

Also, How do I order the columns? So that I can have them in order of Green, Amber, Red


Answers:


The code was

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

        }