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

Pie Chart Grouping

2 Answers 139 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Brandon Strevell
Top achievements
Rank 1
Brandon Strevell asked on 21 Dec 2009, 09:17 PM
Are there any examples of how to group data using the Pie Chart?  All of my attempts end with the entire pie showing just one of the possible groups.

            SeriesMapping seriesMapping = new SeriesMapping(); 
            seriesMapping.SeriesDefinition = new PieSeriesDefinition();
 
            seriesMapping.GroupingSettings.GroupDescriptors.Add(new ChartGroupDescriptor("Baker")); 
 
            ItemMapping itemMappingValue = new ItemMapping("PieID", DataPointMember.YValue, ChartAggregateFunction.Count); 
            seriesMapping.ItemMappings.Add(itemMappingValue); 
 
            ItemMapping itemMappingKey = new ItemMapping("Baker", DataPointMember.LegendLabel); 
            seriesMapping.ItemMappings.Add(itemMappingKey); 
 
            RadChart1.SeriesMappings.Add(seriesMapping); 
 
            List<PieTest> pies = new List<PieTest>(); 
            pies.Add(new PieTest() { PieID = 1, Baker = "John", Crust = "Corn Meal", Filling = "Chili" }); 
            pies.Add(new PieTest() { PieID = 2, Baker = "Peter", Crust = "Graham Cracker", Filling = "Cream Cheese" }); 
            pies.Add(new PieTest() { PieID = 3, Baker = "Paul", Crust = "Graham Cracker", Filling = "Chocolate Cream" }); 
            pies.Add(new PieTest() { PieID = 4, Baker = "Paul", Crust = "Flour", Filling = "Apple" }); 
            RadChart1.ItemsSource = pies; 

So with my example, how would I show a pie chart that represents how many pies each Baker baked?

2 Answers, 1 is accepted

Sort by
0
Accepted
Ves
Telerik team
answered on 23 Dec 2009, 03:56 PM
Hello Brandon,

The scenario you depicted makes perfect sense, but I am afraid RadChart is not designed to support it. The chart grouping has been introduced with Bar series as target type. This is how it works - the items are grouped in series based on the value in a certain field. For pie charts multiple series would mean multiple pies (again -- unsupported scenario).

Luckily, in this case the solution is simple -- you can transform the data manually before sending it to the chart:

var source = pies.GroupBy(pie => pie.Baker).Select(group => new Group() { Baker = group.Key, PiesCount = group.Count() }).ToList();

I have attached a small example showing this approach. I have also updated your Telerik points for drawing our attention to this scenario.

Greetings,
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
Brandon Strevell
Top achievements
Rank 1
answered on 23 Dec 2009, 05:17 PM
Thank you, that works perfectly.
Tags
Chart
Asked by
Brandon Strevell
Top achievements
Rank 1
Answers by
Ves
Telerik team
Brandon Strevell
Top achievements
Rank 1
Share this question
or