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

Sharing a Legend between 2 charts

1 Answer 66 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Otávio
Top achievements
Rank 1
Otávio asked on 26 Jan 2011, 01:14 PM
Exists a way to share the same legend between two chart areas ? I Would like to do something like this:

I'm using a RadChart with the property UseDefaultLayout equals false:
Telerik.Windows.Controls.RadChart telerikChart = new Telerik.Windows.Controls.RadChart();
telerikChart.UseDefaultLayout = false;

I create too a ChartLegend with the property UseAutoGeneratedItems equals true:
ChartLegend legend = new ChartLegend();
legend.UseAutoGeneratedItems = true;
legend.Header = string.Empty;
legend.Name = "MyOwnLegend";

And after I created two ChartAreas
ChartArea firstChart = new ChartArea();
firstChart.LegendName = "MyOwnLegend";
  
ChartArea secondChart = new ChartArea();
secondChart.LegendName = "MyOwnLegend";

I created a PieSeries for each chartarea:
DataSeries firstPieSerie = new DataSeries();
           firstPieSerie.Definition = new DoughnutSeriesDefinition();
           firstPieSerie.Definition.ItemLabelFormat = "p";
           firstPieSerie.Add(new DataPoint() { YValue = 0.215208267, LegendLabel = "Toyota"});
           firstPieSerie.Add(new DataPoint() { YValue = 0.192960612, LegendLabel = "General Motors" });
           firstPieSerie.Add(new DataPoint() { YValue = 0.151830229, LegendLabel = "Volkswagen" });
           firstPieSerie.Add(new DataPoint() { YValue = 0.125964366, LegendLabel = "Ford" });
           firstPieSerie.Add(new DataPoint() { YValue = 0.091152353, LegendLabel = "Honda" });
           firstPieSerie.Add(new DataPoint() { YValue = 0.079093251, LegendLabel = "Nissan" });
           firstPieSerie.Add(new DataPoint() { YValue = 0.079093251, LegendLabel = "PSA" });
           firstPieSerie.Add(new DataPoint() { YValue = 0.064697675, LegendLabel = "Hyundai" });
 
           DataSeries secondPieSerie = new DataSeries();
           secondPieSerie.Definition = new PieSeriesDefinition();
           secondPieSerie.Definition.ItemLabelFormat = "p";
           secondPieSerie.Add(new DataPoint() { YValue = 0.215408267, LegendLabel = "Toyota" });
           secondPieSerie.Add(new DataPoint() { YValue = 0.112460212, LegendLabel = "General Motors" });
           secondPieSerie.Add(new DataPoint() { YValue = 0.111430229, LegendLabel = "Volkswagen" });
           secondPieSerie.Add(new DataPoint() { YValue = 0.115464266, LegendLabel = "Ford" });
           secondPieSerie.Add(new DataPoint() { YValue = 0.011452253, LegendLabel = "Honda" });
           secondPieSerie.Add(new DataPoint() { YValue = 0.019493251, LegendLabel = "Nissan" });
           secondPieSerie.Add(new DataPoint() { YValue = 0.019493251, LegendLabel = "PSA" });
           secondPieSerie.Add(new DataPoint() { YValue = 0.014497275, LegendLabel = "Hyundai" });

Note that I used the same Legend Label for both series, and the same Legend Name for both chart area, but when it is built on screen I had duplicated items. For example, Toyota appears twice and with same color. I would like to know if I can achieve the both chart sharing the same legend.


Thanks.

1 Answer, 1 is accepted

Sort by
0
Missing User
answered on 31 Jan 2011, 08:30 AM
Hello Otávio,

Thank you for contacting Telerik Support.

To be able to have two or more chart areas with a common legend you can review Creating a Chart with custom Layout help topic here:
http://www.telerik.com/help/silverlight/radchart-populating-with-data-creating-chart-declaratively.html
You can also review Manual Legend Items Generation help topic here:
http://www.telerik.com/help/silverlight/radchart-features-chart-legend.html

Let me know whether the proposed solution helps.

All the best,
Polina
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
Chart
Asked by
Otávio
Top achievements
Rank 1
Answers by
Missing User
Share this question
or