Sum a series label

4 posts, 0 answers
  1. Mindy
    Mindy avatar
    4 posts
    Member since:
    Mar 2011

    Posted 21 Aug 2012 Link to this post

    I have the below code.  I am trying to format the series label so that it sums all the values of that series.   I know that the below code snippet labelDefinition.Format = "#Sum"; doesn't work.  Can you recommend something?
    BarSeries ser = new BarSeries();
    ser.ValueBinding = new PropertyNameDataPointBinding("IRBDuration");
    ser.CategoryBinding = new PropertyNameDataPointBinding("EndYear");
    ser.CombineMode = Telerik.Charting.ChartSeriesCombineMode.Stack;
    ser.ShowLabels = true;
      
    ChartSeriesLabelDefinition labelDefinition = new ChartSeriesLabelDefinition();
    labelDefinition.Binding = new PropertyNameDataPointBinding("IRBDuration");
    labelDefinition.VerticalAlignment = System.Windows.VerticalAlignment.Center;
    labelDefinition.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
    labelDefinition.Format = "#SUM";
    ser.LabelDefinitions.Add(labelDefinition);
    chart.Series.Add(ser);
    ser.ItemsSource = _context.Protocols;
  2. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 24 Aug 2012 Link to this post

    Hello Mindy,

    Unfortunately this is not possible out-of-the-box with the ChartView. However using some code behind I think you can get the results you need. Attach a handler to the DataBindingComplete event of the series and apply your logic on changing the labels, in your scenario - hide all labels for a single category, except the last one. The last label should display the sum of the values of all data points for this category. I have attached a simple app to demonstrate this and a snapshot of the output that I get when I run the pp.  

    All the best,
    Petar Marchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Mindy
    Mindy avatar
    4 posts
    Member since:
    Mar 2011

    Posted 24 Aug 2012 Link to this post

    Thanks, I will take a look.  Also, would recommend using the RadChart or the Chartview at this point?
  5. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 27 Aug 2012 Link to this post

    Hi Mindy,

    At this point I would recommend the RadChartView as it is the new charting control.

    Greetings,
    Petar Marchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top