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

Help on updating Legend Labels

3 Answers 56 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ivy
Top achievements
Rank 1
Ivy asked on 17 Dec 2009, 07:09 AM
hi,

I am currently implementing grouping/aggregate function using RadChart.  But I am doing mulitiple SeriesMapping at the same time.  The legend is automatically generating labels however... I need a way to modify the labels so that it could be used to identify which SeriesMapping and grouping at the same time.

Example:

Grouped by "Title"
Mapping of 3 datasets

Legend should look like:
Title 1 DataSet 1
Title 2 DataSet 1
Title 1 DataSet 2
Title 2 DataSet 2
Title 1 DataSet 3
Title 2 DataSet 3

But the smart legend is dong just this:
Title 1
Title 2
Title 1
Title 2
Title 1
Title 2






 

public void BindChart(string aggregateFunction, GroupDescriptorCollection gridGroupDescriptors, object gridItemsSource, string[] dataSets)

 

{

RadChart1.DefaultView.ChartArea.AdditionalYAxes.Clear();

RadChart1.ItemsSource = Translate(gridItemsSource);

RadChart1.SeriesMappings.Clear();

 

ChartAggregateFunction aggFunct = (ChartAggregateFunction)Enum.Parse(typeof(ChartAggregateFunction), aggregateFunction, true);

 

 

foreach (string dataSet in dataSets)

 

{

 

SeriesMapping mapping = new SeriesMapping();

 

mapping.ItemMappings.Clear();

mapping.ItemMappings.Add(

new ItemMapping(dataSet, DataPointMember.YValue, aggFunct));

 

 

mapping.SeriesDefinition =

new BarSeriesDefinition();

 

#region

 

Assign Axis Y

 

 

//if (RadChart1.SeriesMappings.Count > 1)

 

 

//{

 

 

// RadChart1.DefaultView.ChartArea.AdditionalYAxes.Add(GenerateYAxis(dataSet));

 

 

// mapping.SeriesDefinition.AxisName = dataSet;

 

 

//}

 

#endregion

 

ChartGroupDescriptorCollection chartGroupDescriptors = new ChartGroupDescriptorCollection();

 

 

foreach (GroupDescriptor descriptor in gridGroupDescriptors)

 

mapping.GroupingSettings.GroupDescriptors.Add(

new ChartGroupDescriptor(descriptor.Member, descriptor.MemberType));

 

 

GroupDescriptor lastGroupDescriptor;

 

 

if (gridGroupDescriptors.Count > 0 && aggregateFunction.ToLower() != "none")

 

{

lastGroupDescriptor = gridGroupDescriptors[gridGroupDescriptors.Count - 1];

mapping.ItemMappings.Add(

new ItemMapping(lastGroupDescriptor.Member, DataPointMember.XCategory));

 

}

RadChart1.SeriesMappings.Add(mapping);

}

}

3 Answers, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 22 Dec 2009, 08:13 AM
Hi,

RadChart will do this automatically for you. I believe you have already found the corresponding online example. In addition, I have attached a simplified version with 2 SeriesMapping objects.

Kind regards,
Ves
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ivy
Top achievements
Rank 1
answered on 23 Dec 2009, 01:45 AM
Thank you for your reply.  But I believe I am already doing this multiple series mappings.  The chart is correctly graphing as I programmed with several mappings.  But I am not happy with the automatic legend created as I grouped and I want to tweak it to my liking.  Is that possible?  How can I access the automatic legend and perhaps append something to it?
0
Ves
Telerik team
answered on 23 Dec 2009, 03:58 PM
Hello,

Let me start with my apologies -- it seems I have attached an example which is somewhat erroneous - adding the same mappings twice. I have attached the correct version now. Note, that there is only one series mapping and the legend items contain information for both - region and year.

As for updating the legend items directly - you can wire the DataBound event of RadChart and loop through the data series (RadChart1.DefaultView.ChartArea.DataSeries). You can modify each DataSeries object's LegendLabel property - the change will be reflected in the legend immediately:

RadChart1.DefaultView.ChartArea.DataSeries[0].LegendLabel = "My Label"

Best regards,
Ves
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
Ivy
Top achievements
Rank 1
Answers by
Ves
Telerik team
Ivy
Top achievements
Rank 1
Share this question
or