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

Pie chart is not showing different colors

1 Answer 44 Views
Chart
This is a migrated thread and some comments may be shown as answers.
kalyan gupta
Top achievements
Rank 1
kalyan gupta asked on 26 Aug 2010, 10:58 AM

Hi @

I am developing an application using SL 4, VS 2010. I am using Telerik Silverlight Chart controls in the application.

I am displaying Pie chart.

I have to show count of Employees in each organisation in Pie chart with Organisation in Legend positions.

I am getting correct chart but all the organisations in same color.
Please let me know i am doing something wrong in following code snippet.

/// <summary>
       /// Load pie chart
       /// </summary>
       /// <param name="selectionData">FilterResult list</param>
       private void LoadPieChart(FilterResult[] selectionData)
       {
           Binding binding = new Binding("DefaultView.ChartLegendPosition");
           binding.Mode = BindingMode.TwoWay;
           LegendPosition.DataContext = trcRadPieChart;
           LegendPosition.SetBinding(RadComboBox.SelectedValueProperty, binding);
           Binding binding2 = new Binding("DefaultView.ChartLegend.LegendItemMarkerShape");
           binding2.Mode = BindingMode.TwoWay;
           LegendItemMarkerShape.DataContext = trcRadPieChart;
           LegendItemMarkerShape.SetBinding(RadComboBox.SelectedValueProperty, binding2);
           this.trcRadPieChart.DefaultView.ChartTitle.Content = "Employee per Organisation";
           this.trcRadPieChart.DefaultView.ChartArea.LabelFormatBehavior = LabelFormatBehavior.None;
           this.SetMappings(this.trcRadPieChart);
           this.trcRadPieChart.ItemsSource = selectionData;
           isPieChartSeriesMappingAdded = true;
           this.trcRadPieChart.DefaultView.ChartLegend.LegendItemMarkerShape = MarkerShape.Circle;
       }
       /// <summary>
       /// Set the mapping
       /// </summary>
       /// <param name="chart">RadChart</param>
       private void SetMappings(RadChart chart)
       {
           SeriesMapping seriesMapping = new SeriesMapping();
           seriesMapping.SeriesDefinition = new PieSeriesDefinition();
           seriesMapping.GroupingSettings.GroupDescriptors.Add(new ChartGroupDescriptor("ORGANISATION"));
           seriesMapping.GroupingSettings.ShouldCreateSeriesForLastGroup = true;
           ItemMapping itemMapping = new ItemMapping("EMPLOYEE", DataPointMember.YValue);
           seriesMapping.ItemMappings.Add(itemMapping);
           itemMapping = new ItemMapping("ORGANISATION", DataPointMember.LegendLabel);
           seriesMapping.ItemMappings.Add(itemMapping);
           chart.SeriesMappings.Clear();
           chart.SeriesMappings.Add(seriesMapping);
       }

 

1 Answer, 1 is accepted

Sort by
0
Bartholomeo Rocca
Top achievements
Rank 1
answered on 26 Aug 2010, 11:36 AM
Hello Kalyan,

Because of your grouping settings you are effectively creating multiple DataSeries, while Pie chart can only display single series correctly -- try setting seriesMapping.GroupingSettings.ShouldFlattenSeries = true.


Greetings,
Bart
Tags
Chart
Asked by
kalyan gupta
Top achievements
Rank 1
Answers by
Bartholomeo Rocca
Top achievements
Rank 1
Share this question
or