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

Multi-color bars for one series

2 Answers 65 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Ahmed
Top achievements
Rank 1
Ahmed asked on 18 Nov 2011, 06:00 AM
Hello,

I am programatically drawing a bar RadChart to display ratings count for some products. The valid ratings that I use are 0, 1, 2, 3, 4, 5. I count the rated products and plot them against the rating. At the end, I get six bars (0 to 5), which is correct. The thing that I want to do is always show the bar for rating 0 in RED color. Rest continues to work skin-based.

Someone told me to use another series for rating 0 only and give it red color but I don't want to use it as it will move the bars of my first series to a side to make place for the bars for the second one however the second series would never have any value for any other rating except 0.

Can you tell me a solution in which I achieve this in one series only?

2 Answers, 1 is accepted

Sort by
0
Accepted
Petar Marchev
Telerik team
answered on 22 Nov 2011, 03:08 PM
Hi Ahmed,

One way to achieve this is by attaching to the RadChart's ItemDataBound event. You can put your custom logic on coloring in the event handler.

Here is some code:
private void CreateProgramaticallyRadChart()
{
     RadChart radChart = new RadChart();
 
     radChart.ItemDataBound += new EventHandler<ChartItemDataBoundEventArgs>(radChart_ItemDataBound);
 
     radChart.DataSource = items;
     radChart.DataBind();
}
void radChart_ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
{
    if (e.SeriesItem.XValue == 0)
    {
        e.SeriesItem.Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
    }
}

I hope this helps.

All the best,
Petar Marchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Ahmed
Top achievements
Rank 1
answered on 22 Nov 2011, 07:22 PM
Hi Petar,

Thanks a lot for your reply. Although it didn't help me directly as I'm not binding the chart to a source but still it showed me the way and I managed to get the desired result.

Thanks again :)
Tags
Chart (Obsolete)
Asked by
Ahmed
Top achievements
Rank 1
Answers by
Petar Marchev
Telerik team
Ahmed
Top achievements
Rank 1
Share this question
or