4

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!

Hooplator15
  • 1,540
  • 7
  • 31
  • 58
  • Have you looked at the examples? There is one specifically for `LabelFormatter`. FYI the example graphs are on a website so you can find a feature you're looking for and then look at that example: http://oxyplot.org/ExampleBrowser/ About a tenth of the way down, under the heading "Axis examples", is "LabelFormatter". – Steve Jul 23 '14 at 19:41
  • No, I had no idea that those examples existed. I was just going off of google searches. I'll have a look. Certainly feel dumb now... Thank you! – Hooplator15 Jul 23 '14 at 19:46
  • Nah, I went through the same thing. Bookmark that. I believe the code for those examples is included in the OxyPlot sources so you can build and run it yourself if you like, but I didn't see much need for that. Usually, find an example that does something similar, browse the code, then tweak yours. By the way, if that helps to solve your problem let me know and I'll move it into an answer. – Steve Jul 23 '14 at 19:47
  • @Steve the website you pointed to does not exist anymore. You would have to download the github code and compile the ExampleBrowser by yourself (unless it is available elsewhere). – lnjuanj Jun 14 '21 at 18:44

2 Answers2

7

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);
AwkwardCoder
  • 24,893
  • 27
  • 82
  • 152
0
        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.