【问题标题】:Telerik WPF Legend Question StumpedTelerik WPF 传奇问题难倒
【发布时间】:2011-08-14 12:33:07
【问题描述】:

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

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

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

【问题讨论】:

    标签: wpf charts telerik legend


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2010-10-22
      • 2015-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-19
      相关资源
      最近更新 更多