wpf OxyPlot : ColumnSeries/BarSeries 显示每列的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20886835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 10:22:33  来源:igfitidea点击:

OxyPlot : ColumnSeries/BarSeries display value of each column

wpfstackedbarseriesoxyplot

提问by Tvd

In my WPF app, I use OxyPlot. I bind my data to the PlotModel and all is working well.

在我的 WPF 应用程序中,我使用 OxyPlot。我将数据绑定到 PlotModel 并且一切正常。

I want to display the value of each column on the chart. Is it possible?

我想在图表上显示每一列的值。是否可以?

For reference, this example of BarSerieson site, I wish to show actual value of Apples of 2009, 2010 & 2011 respectively on each column. i.e. value of Value1 for the 2009Apples column, Value2 for 2010Apples and so on.

作为参考,这个现场的BarSeries示例,我希望在每列上分别显示2009年、2010年和2011年苹果的实际价值。即 2009Apples 列的 Value1 的值,2010Apples 列的 Value2 等。

I looked up at the APIof the BarSeries (For WPF ColumnSeries used interchangeably). Tutorials of Bar & other plots. But couldn't find such thing anywhere.

我查看了 BarSeries 的 API(对于 WPF ColumnSeries 可互换使用)。条形图和其他图的教程。但是在任何地方都找不到这样的东西。

How do I achieve this?

我如何实现这一目标?

回答by Steve

Yes, just set the LabelFormatStringproperty of your series.

是的,只需设置LabelFormatString系列的属性。

var theSeries = new ColumnSeries();
theSeries.LabelFormatString = "{0:F2}"; // Example: 1.2311 will display like "1.23"

// Add your columns
theSeries.Items.Add(new ColumnItem(someValue);
// ...

There is also an optional property you can set called LabelPlacement. The default value is LabelPlacement.Outside:

您还可以设置一个名为 的可选属性LabelPlacement。默认值为LabelPlacement.Outside

theSeries.LabelPlacement = LabelPlacement.Middle;