This is a migrated thread and some comments may be shown as answers.

Assign different color for each bar (Telerik Reporting Chart Q2 2011))

1 Answer 170 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Fadhli
Top achievements
Rank 1
Fadhli asked on 30 Jan 2012, 10:37 AM
Hi.. I'm using Telerik Reporting Q2 2011.

I have a problem with my Telerik reporting bar chart.  Everything works perfectly , however i need my chart to have different color for each bar.
I've set my chart LegendDisplayMode to itemLabels, make sure my series pallete is not set and write these codes

public WebCategoryBarChart()
      {
           //
           // Required for telerik Reporting designer support
           //
           InitializeComponent();
 
           this.chart1.Series[0].Appearance.LegendDisplayMode = ChartSeriesLegendDisplayMode.ItemLabels;
 
           Color[] barColors = new Color[8]{
               Color.Purple,
               Color.SteelBlue,
               Color.Aqua,
               Color.Yellow,
               Color.Navy,
               Color.Green,
               Color.Blue,
               Color.Red
           };
           int i = 0;
           foreach (ChartSeriesItem item in chart1.Series[0].Items)
           {
               item.Appearance.FillStyle.MainColor = barColors[i++];
           }
 
          
           //
           // TODO: Add any constructor code after InitializeComponent call
           //
       }

But still the default color of the bars is still there..

How should i go about this..?

1 Answer, 1 is accepted

Sort by
0
Elian
Telerik team
answered on 31 Jan 2012, 12:24 PM
Hi Fadhli,

The code is correct, but would only work if the chart is not declaratively databound i.e. you create the chart series and items programmatically. If the chart is databound, you can use custom palettes for this purpose - in the chart properties you can find a property called CustomPalettes - there you can define your own palettes with the desired colors. Afterwards in chart's property SeriesPalette you can specify the palette you have created and the chart will use it when assigning colors to the bars.

All the best,
Elian
the Telerik team

Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

Tags
General Discussions
Asked by
Fadhli
Top achievements
Rank 1
Answers by
Elian
Telerik team
Share this question
or