.NET Framework Bookmark and Share   
 index > Chart Controls for .NET Framework > I want to specify the colors of my bar chart
 

I want to specify the colors of my bar chart

I have a bar chart that I am creating and I want the first bar to be one specific color and the second one to be another specific color. How do I do this? I like the 'berry' palette and I specify that in my chartarea now and it's great, but one of the colors is too dark. So if I could just do something similar and pick my own colors, I'd be set.

Thanks!
apple17
You can select predifined palette on the series:

Chart.Series[0].Palette = ChartColorPalette.Berry;

You can also define custom palette if you want using Chart.PaletteCustomColors... but the simpliest apptoach is to set individual data point Color property:

Chart.Series[0].Points[0].Color = Color.Red;
Chart.Series[0].Points[1].Color = Color.Green;
...

Alex.
http://blogs.msdn.com/alexgor
Alex Gorev
You can select predifined palette on the series:

Chart.Series[0].Palette = ChartColorPalette.Berry;

You can also define custom palette if you want using Chart.PaletteCustomColors... but the simpliest apptoach is to set individual data point Color property:

Chart.Series[0].Points[0].Color = Color.Red;
Chart.Series[0].Points[1].Color = Color.Green;
...

Alex.
http://blogs.msdn.com/alexgor
Alex Gorev

Thank you.

Ok, so I'm new to this, a couple of questions. I think I like the idea of setting up a custom palette, but I can't find code to do this and don't understand how to do it myself in vb.

for the code above, when do you execute it? When I do it at page load, I get a subscript out of bounds error.

apple17
This is apparently what I need to do, but again, I don't know when...is there an event in building the chart where I can execute this? If I execute on page load, I get

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index


Thanks for your assistance.

apple17
For beginners I recommend to check out Chart Sample Environment here: http://code.msdn.microsoft.com/mschart

Alex.
http://blogs.msdn.com/alexgor
Alex Gorev
got it, thanks, it was in the 'onDataBound' code. It works now.
apple17

You can use google to search for other answers

Custom Search

More Threads

• How go I get the HTML for the chart image AREA map
• MOSS 2007 Blank Chart Image
• Need .Net component for ontology graphics
• Creating a simple chart by two columns.
• Data points insertion error. Only 1 Y values can be set for this data series.
• Bind chart series to object
• tick marks show through markers
• chart with no data
• Next Version
• how to set the chart control's Title Height or width?