Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change colors of specific data points in a "series" of a chart?

Tags:

c#

charts

screenshot of currently appearing chartI don't know if can make it clear otherwise, So here is the code:-

    Series series2 = null;
    for (int i = 0; i < 4; i++)
    {
        series2 = chart2.Series.Add(subjectnames[i]);
    }
    for (int i = 0; i < 4; i++)
    {
        series2.Points.Add(attemptper[i]);
        series2.Points.Add(correctper[i]);
    }

Now, I just want to display "attemptper" bars in different color than "correctper" bars. By default they are appearing in greyish-blue color. How do I get it done?

The charts appear all in bluish color. I want them to appear in different colors. I think I haven't added the data correctly to the chart for this to achieve?

like image 594
vish213 Avatar asked Mar 14 '13 07:03

vish213


People also ask

How do I change the color of a data series?

To change the color of a data series: Select the data series you wish to edit. Click the Format button on the Chart toolbar (or double-click the data series). Use the Format Data Series dialog box to pick a new color. Click the OK button to accept the Data Series color changes.

How do I change the selected data in an Excel chart?

Edit or rearrange a series Right-click your chart, and then choose Select Data. In the Legend Entries (Series) box, click the series you want to change. Click Edit, make your changes, and click OK. Changes you make may break links to the source data on the worksheet.


1 Answers

You change the color on the series point(index) like this:

        Chart1.Series[1].Points[0].Color = Color.Red

Getting the chart to repaint might also take some code, depending on what you're doing. For me, I wanted to animate my chart, building the data point (a column) dynamically as the program ran, showing the status of some work I was doing, which required this:

        Chart1.Series.ResumeUpdates()
        Chart1.Series[1].Points.Item[0].YValues = Double(1) {MyNewValue, 0}
        Chart1.Series[1].Points[0].Color = Color.Red
        Chart1.DataBind()
        Chart1.Series.Invalidate()
        Chart1.Series.SuspendUpdates()
like image 75
Brian Avatar answered Oct 28 '22 16:10

Brian