Adding string to autogenerated item legend label

3 posts, 1 answers
  1. Oliver
    Oliver avatar
    33 posts
    Member since:
    Jan 2011

    Posted 04 Nov 2012 Link to this post

    Is there a way to add in extra wordings to the auto generated legend item label?
    I simply wanted to an aggregation type used in from the the legend label heading. So instead of a label showing "Outstanding category" from the dataseries, I wanted a "Count of Outstanding category" or "Sum of Outstanding Category" as the legend label.

    Any suggestions will be helpful. Thanks
  2. Answer
    Petar Kirov
    Admin
    Petar Kirov avatar
    425 posts

    Posted 07 Nov 2012 Link to this post

    Hi Oliver,

    There are several ways to modify the ChartLegend content.

    The first is to manually create the legend items, like demonstrated in this help topic. 

    You can also try using the LayoutUpdated event to change the already present content: 
    this.RadChart1.DefaultView.ChartLegend.LayoutUpdated +=
        ChartLegend_LayoutUpdated;
     
    void ChartLegend_LayoutUpdated(object sender, EventArgs e)
    {
        //Do not forget to unsubscribe, or you will cause a Layout Cycle
        this.RadChart1.DefaultView.ChartLegend.LayoutUpdated -=
            ChartLegend_LayoutUpdated;
     
        foreach (var legendItem in
            (this.RadChart1.DefaultView.ChartLegend as ItemsControl).Items)
        {
            (legendItem as ChartLegendItem).Label = "Count of " +
                (legendItem as ChartLegendItem).Label;
        }
    }

    But perhaps the easiest one is set the the LegendLabel property of the series definition to the string you want to have in the corresponding legend item.

    If you have any further questions feel free to ask.
     
    Greetings,
    Petar Kirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Oliver
    Oliver avatar
    33 posts
    Member since:
    Jan 2011

    Posted 08 Nov 2012 Link to this post

    Hi Petar,

    Thanks for the reply. I got it working but not in an event like you suggested.

Back to Top