How to change OxyPlot Y-Axis string format?

Hooplator15 picture Hooplator15 · Jul 23, 2014 · Viewed 7.5k times · Source

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!

Answer

AwkwardCoder picture AwkwardCoder · Jul 24, 2014

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