开发者

Telerik WPF Legend Question Stumped

开发者 https://www.devze.com 2023-03-01 01:31 出处:网络
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 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 doin开发者_高级运维g wrong? The legend shows the title, but it does not show the legend label that has been associated with each datapoint. Why?

I have searched for a few hours and I took there sample verbatim and still the legend will not show the LegendLabel. I started with the pie as I thought it would be the easiest.

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";


I have not created the DataPoints individually before. However, here is the code I use to assign information from a DataView to my pie chart. It works fine for me:

//Assigns the DataView to the grid
SeriesMapping mySeries = new SeriesMapping();
mySeries.SeriesDefinition = new PieSeriesDefinition();
mySeries.SeriesDefinition.Appearance.StrokeThickness = 2;
mySeries.ItemMappings.Add(new ItemMapping("Value", DataPointMember.YValue));
mySeries.ItemMappings.Add(new ItemMapping("Manufacturer", DataPointMember.LegendLabel));
pieChart.SeriesMappings.Add(mySeries);

pieChart.ItemsSource = myPieChartView;

The differences I see here are that you are assigning the information to the DataSeries instead of the SeriesMappings. Maybe that causes an issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消