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

2 posts, 0 answers
  1. Lanto
    Lanto avatar
    8 posts
    Member since:
    Jan 2008

    Posted 12 Oct 2010 Link to this post

    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;

     

  2. Evgeni "Zammy" Petrov
    Admin
    Evgeni "Zammy" Petrov avatar
    168 posts

    Posted 15 Oct 2010 Link to this post

    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
Back to Top