Search code examples
c#wpfoxyplot

How to change OxyPlot Y-Axis string format?


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!


Solution

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