How to change OxyPlot Y-Axis string format?

坚强是说给别人听的谎言 提交于 2019-12-10 19:38:43

问题


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

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

I am using OxyPlot to produce the chart in 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!


回答1:


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

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



回答2:


        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.



来源:https://stackoverflow.com/questions/24918366/how-to-change-oxyplot-y-axis-string-format

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!