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

Relative Value at the Bars (percentage )

1 Answer 120 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Karim
Top achievements
Rank 1
Karim asked on 28 Nov 2012, 07:37 AM

Hello,

I am using the telerik winform components specially the bar char view. I created a bar series where we set the combine mode to bar100 so that we can see the percentage values at the x-axes. My problem is that we want to display the percentage values directly at the bars instead at absolute values. 

Does anybody know how I can display the relative value at the bars?

Karim

1 Answer, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 03 Dec 2012, 07:38 AM
Hello Karim,

Thank you for writing.

You can use RadChartView's LabelFormatting event to customize the text displayed in the labels. Here is a code snippet which demonstrates how to do it in your case:
private void radChartView1_LabelFormatting(object sender, ChartViewLabelFormattingEventArgs e)
{
  CategoricalDataPoint point = e.LabelElement.DataPoint as CategoricalDataPoint;
 
  double total = 0d;
 
  foreach (BarSeries series in this.radChartView1.Series)
  {
    foreach (CategoricalDataPoint dp in series.DataPoints)
    {
      if (dp.Category.Equals(point.Category) && dp.Value.HasValue)
      {
        total += dp.Value.Value;
      }
    }
  }
 
  e.LabelElement.Text = string.Format("{0:P2}", (point.Value / total));
}

I hope this will be useful. Should you have further questions, I would be glad to help.
 
Kind regards,
Ivan Petrov
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
ChartView
Asked by
Karim
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Share this question
or