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

Graph on percent show count in label

1 Answer 88 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Becky Bryda
Top achievements
Rank 1
Becky Bryda asked on 10 Apr 2012, 01:53 PM
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?

1 Answer, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 11 Apr 2012, 12:08 PM
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,
Evgenia
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.
Tags
Chart (Obsolete)
Asked by
Becky Bryda
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Share this question
or