1

我需要即时生成图表,只有当我收到响应时,我才会知道要生成哪种类型的图表。

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

我已经搜索了几个小时,并且逐字逐句地拿了样本,但图例仍然不会显示 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";
4

1 回答 1

0

我之前没有单独创建数据点。但是,这是我用来将数据视图中的信息分配给我的饼图的代码。这对我来说可以:

//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。也许这会导致问题。

于 2011-05-04T15:17:26.920 回答