Telerik WPF传奇问题难倒

时间:2011-04-28 08:34:04

标签: wpf charts telerik legend

我需要动态生成图形,只有当我收到响应时,我才会知道要生成什么类型​​的图形。

我已经尝试了大约一个小时但无法弄明白。我究竟做错了什么?图例显示标题,但不显示与每个数据点关联的图例标签。为什么呢?

我已经搜索了几个小时,我在那里逐字采样,但传说中的传说仍然不会显示LegendLabel。我从馅饼开始,因为我认为这是最简单的。

我错过了什么?

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 个答案:

答案 0 :(得分:0)

之前我没有单独创建过DataPoints。但是,这是我用来将DataView中的信息分配给我的饼图的代码。它适用于我:

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

我在这里看到的不同之处在于您将信息分配给DataSeries而不是SeriesMappings。也许这会导致问题。