Graph on percent show count in label

Thread is closed for posting
2 posts, 0 answers
  1. Becky Bryda
    Becky Bryda avatar
    9 posts
    Member since:
    Sep 2006

    Posted 10 Apr 2012 Link to this post

    I've been trying to figure this out for a day now and am no closer to a solution. I want to bar graph items on a percentage scale, but for each bar show in the label the count that corresponds to that percentage. Can you point me to a working sample of this? Preferably one that is database bound so that i can see how my dataset should be coming back from SQL too?
  2. Evgenia
    Evgenia avatar
    1437 posts

    Posted 11 Apr 2012 Link to this post

    Hello Becky,

    Since you are new to our chatring control I suggest that you refer to our documentation and online examples that I believe will get you started properly.
    Onto your questions:
    There is an online sample with source code provided where the chart is populated with data from the Nortwind database. You may also find our topic helpful for your scenario.
    By default the chart series show the YValue as Label for each corresponding chart item. Also by default the YAxis automatically arranges itself according to the data shown. Knowing this what you'll need to do is to convert the YAxis labels to percentage. You can achieve this convertion with the following formula:
    Divide the current YAxis value to the total of all Bar Values and append percentage sign.
    Please note that this should be done in either BeforeLayout or PrePaint events since they are thrown before the axis labels are drawn. Here's an example:

    void RadChart1_BeforeLayout(object sender, EventArgs e)
          for (int i = 0; i < RadChart1.PlotArea.YAxis.Items.Count; i++)
              double totalOfAllItems = RadChart1.Series[0].Items.Sum(s => s.YValue);
              decimal calculatedPercentage = RadChart1.PlotArea.YAxis.Items[i].Value / (decimal)totalOfAllItems;
              RadChart1.PlotArea.YAxis.Items[i].TextBlock.Text = calculatedPercentage.ToString("P");

    All the best,
    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.
Back to Top