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

Adding string to autogenerated item legend label

2 Answers 69 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 05 Nov 2012, 03:31 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Petar Kirov
Telerik team
answered on 07 Nov 2012, 05:07 PM
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.

0
Oliver
Top achievements
Rank 1
answered on 08 Nov 2012, 07:00 AM
Hi Petar,

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

Tags
Chart
Asked by
Oliver
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
Oliver
Top achievements
Rank 1
Share this question
or