Telerik WPF Legend 问题难住了

发布于 2024-11-03 23:33:15 字数 1522 浏览 0 评论 0原文

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

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

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

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?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

要走就滚别墨迹 2024-11-10 23:33:15

我之前没有单独创建过数据点。但是,这是我用来将 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。也许这会导致问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文