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

What am I doing wrong; Legend will not display.

1 Answer 52 Views
Chart
This is a migrated thread and some comments may be shown as answers.
kevin
Top achievements
Rank 1
kevin asked on 28 Apr 2011, 09:03 AM
I need to generate graphs on the fly and only when I receive the response will I know what type of graph to generate.

I have been trying for about a hour and cannot figure it out.  What am I doing wrong?  The legend shows the title, but it does not show the legend label that has been associated with each datapoint.  Why?

What am I missing?
           
var chartArea = new ChartArea();
 chartArea.LegendName = "test";
             
 var pieSeries = new DataSeries
 {
     Definition = new PieSeriesDefinition
     {
         InteractivitySettings =
             {HoverScope = InteractivityScope.None,
              SelectionScope = InteractivityScope.Item,
               SelectionMode = ChartSelectionMode.Single
              }
     }
 };
             
 
pieSeries.Definition.ItemLabelFormat = "p";
pieSeries.Add( new DataPoint() { YValue = 0.215208267, LegendLabel = "Toyota" } );
pieSeries.Add( new DataPoint() { YValue = 0.192960612, LegendLabel = "General Motors" } );
pieSeries.Add( new DataPoint() { YValue = 0.151830229, LegendLabel = "Volkswagen" } );
pieSeries.Add( new DataPoint() { YValue = 0.125964366, LegendLabel = "Ford" } );
pieSeries.Add( new DataPoint() { YValue = 0.091152353, LegendLabel = "Honda" } );
pieSeries.Add( new DataPoint() { YValue = 0.079093251, LegendLabel = "Nissan" } );
pieSeries.Add( new DataPoint() { YValue = 0.079093251, LegendLabel = "PSA" } );
pieSeries.Add( new DataPoint() { YValue = 0.064697675, LegendLabel = "Hyundai" } );
             
chartArea.DataSeries.Add(pieSeries);
RadChart1.DefaultView.ChartLegend.UseAutoGeneratedItems = true;
RadChart1.DefaultView.ChartArea = chartArea;
RadChart1.DefaultView.ChartLegend.Header = "Legend test";

            

1 Answer, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 02 May 2011, 09:16 AM
Hi kevin,

Generally it is not necessary to recreate the default ChartArea instance (RadChart.DefaultView.ChartArea) but if you would like to stick to that approach, you will need to properly associate your ChartArea with the respective ChartLegend (note that ChartArea.LegendName is primarily useful in XAML scenarios and it assumes the ChartLegend.Name property is set to the same value). In your scenario it is better to associate the ChartArea and the ChartLegend like this:
chartArea.Legend = RadChart1.DefaultView.ChartLegend;

Hope this helps.


All the best,
Giuseppe
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
kevin
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Share this question
or