We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Changing chart colours of each bar in the same series

Thread ID:





59957 Apr 25,2007 07:39 AM Apr 26,2007 05:31 AM Windows Forms 2
Tags: Chart
Chong Wong
Asked On April 25, 2007 07:39 AM

Hi Syncfusion,

Is it possible to change the colour of each bar in the same single series?

Eg: take your example:

Each bar is the same colour. I would like to make each bar a different colour if possible? How to do it if possible?

Thanks in advance!


Ramya R [Syncfusion]
Replied On April 25, 2007 09:25 AM

Hi Chong,

Thanks for your interest in Syncfusion Products.

You can set specific color to each bar by using the PrepareStyle event of the Chart series or by using the Styles[seriesindex].Interior property as shown in the code snippets below,

1. private void Series1_PrepareStyle(object sender, ChartPrepareStyleInfoEventArgs args)
ChartSeries series=sender as ChartSeries;
if (args.Index == 0)
args.Style.Interior = new BrushInfo(Color.Green);
else if (args.Index == 1)
args.Style.Interior = new BrushInfo(Color.Bisque);
else if (args.Index == 2)
args.Style.Interior = new BrushInfo(Color.Cyan);
else if (args.Index == 3)
args.Style.Interior = new BrushInfo(Color.Blue);
else if (args.Index == 4)
args.Style.Interior = new BrushInfo(Color.Red);



2. series.Styles[0].Interior= new BrushInfo(Color.Red);
series.Styles[1].Interior= new BrushInfo(Color.Green);
series.Styles[2].Interior= new BrushInfo(Color.Blue);
series.Styles[3].Interior= new BrushInfo(Color.Violet);
series.Styles[4].Interior= new BrushInfo(Color.BurlyWood);

or if your intention is to have different colors for the series each item when the sample is executed it can be done as shown in the code snippet below,

Random r=new Random();
for(int i=0;iseries.Styles[i].Interior= new BrushInfo(Color.FromArgb(r.Next(0,255),r.Next(0,255),r.Next(0,255)));

Let me know whether this helps you.

Thanks & Regards,

Chong Wong
Replied On April 26, 2007 05:31 AM

Hi Ramya,

Thank your for the code snippets, it works perfectly!

Thanks for your help again!



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.