Multi-color bars for one series

Thread is closed for posting
3 posts, 1 answers
  1. Ahmed
    Ahmed avatar
    6 posts
    Member since:
    Sep 2011

    Posted 18 Nov 2011 Link to this post

    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. Answer
    Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 22 Nov 2011 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ahmed
    Ahmed avatar
    6 posts
    Member since:
    Sep 2011

    Posted 22 Nov 2011 Link to this post

    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 :)
Back to Top