wpf 如何更改 OxyPlot Y 轴字符串格式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24918366/
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 12:12:14  来源:igfitidea点击:

How to change OxyPlot Y-Axis string format?

c#wpfoxyplot

提问by John August

Can anyone tell me how to change the Y axis string format??

谁能告诉我如何更改 Y 轴字符串格式?

I have Y-Axis percentages that I want to add the percent sign to.

我有要添加百分号的 Y 轴百分比。

I am using OxyPlot to produce the chart in wpf.

我正在使用 OxyPlot 在 wpf 中生成图表。

Here is my attempt, but it is NOT working:

这是我的尝试,但它不起作用:

Func<double, string> formatFunc = (x) => string.Format("{000.00}%", x);

        formatFunc = new Func<double,string>("{0}");
        // Add the plot to the window
        line.YAxis.LabelFormatter = formatFunc;

This produces null reference error.

这会产生空引用错误。

Thanks!

谢谢!

回答by AwkwardCoder

This is an example I've used previously to format the x-axis on an oxy-plot:

这是我之前用来在 oxy-plot 上格式化 x 轴的示例:

var xAxis = new DateTimeAxis
{
    Position = AxisPosition.Bottom,
    StringFormat = "dd/MM/yyyy",
    Title = "End of Day",
    IntervalLength = 75,
    MinorIntervalType = DateTimeIntervalType.Days,
    IntervalType = DateTimeIntervalType.Days,
    MajorGridlineStyle = LineStyle.Solid,
    MinorGridlineStyle = LineStyle.None,
};

Plot = new PlotModel();
Plot.Axes.Add(xAxis);

回答by KateKotova

        this._PlotModel.Axes.Add( new LinearAxis
        {
            Position = AxisPosition.Left,
            Minimum = 0.025,
            Maximum = 0.205,
            StringFormat = "0.00%",
            MajorStep = 0.005
        } );

- add percents as ratio: 20.5% --> 0.205, 0.5% --> 0.005, etc.

- 添加百分比作为比率:20.5% --> 0.205、0.5% --> 0.005 等。