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

How to get legend names from data in a 3D Pie chart

1 Answer 75 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Lanto
Top achievements
Rank 1
Lanto asked on 12 Oct 2010, 06:43 PM

I need the legend names to be populated from the ItemsSource. How can I do this?

--------------------------------
pieChart.DefaultSeriesDefinition = 

 

new Pie3DSeriesDefinition();

 

 

pieChart.DefaultView.ChartLegend.UseAutoGeneratedItems = 

 

true;

 

 

pieChart.DefaultView.ChartLegend.Header = 

 

"";

 

pieChart.DefaultView.ChartArea.Extensions.Add(

 

new CameraExtension());

 

 

var data = new List<Data>

{

    

 

new Data { Name = "ABC", Amount = 1300 },

 

   

 

new Data { Name = "XYZ", Amount = 290 }

 

};

pieChart.ItemsSource = data;

 

1 Answer, 1 is accepted

Sort by
0
Evgeni "Zammy" Petrov
Telerik team
answered on 15 Oct 2010, 10:06 AM
Hi Lanto,

 Thank you for contacting us with your question.
You can easily do that if you use Manual Series Mapping.

Here is sample code for your case:

SeriesMapping seriesMapping = new SeriesMapping();
seriesMapping.SeriesDefinition = new Pie3DSeriesDefinition();
seriesMapping.ItemMappings.Add(new ItemMapping("Amount", DataPointMember.YValue));
seriesMapping.SeriesDefinition.LegendDisplayMode = LegendDisplayMode.DataPointLabel; 
seriesMapping.ItemMappings.Add(new     ItemMapping("Name",DataPointMember.LegendLabel));
pieChart.SeriesMappings.Add(seriesMapping);

With the previous snippet you can create mapping between your data and parts of the chart.
Amount will be mapped to YValue for a DataPoint.
Name will be mapped to LegendLabel.

It is important to tell the chart to take the LegendLabel from the data point itself.
seriesMapping.SeriesDefinition.LegendDisplayMode = LegendDisplayMode.DataPointLabel; 

Here you can read more about manual series mapping:
http://www.telerik.com/help/silverlight/radchart-populating-with-data-data-binding-with-manual-series-mapping.html
 
Regards,
Evgeni "Zammy" Petrov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Chart
Asked by
Lanto
Top achievements
Rank 1
Answers by
Evgeni "Zammy" Petrov
Telerik team
Share this question
or