Search code examples
c#oxyplot

Oxyplot set XAsis increasing by 0.5


I can't manage to set the xAxis properly I would like interval increasing by 0.5:

|--|----|---|
0  0.5  1  1.5  and so on

I use this:

PositionModel.Axes.Add(new CategoryAxis { 
    Position = AxisPosition.Bottom, Minimum = 9,
    Maximum = 28,
    Key = "XAsis", 
    MajorStep = 1, // useless ?
    MinorStep = 0.5  // useless ?
});

But this code doesn't produce the desired result (increasing by 1 instead).

Besides I don't really know what exactly Marjor/MinorStep is.

Documentation is really really light... unfortunatly

PS: I am really upset to see negative vote without explanation


Solution

  • You should use Axis instead of CategoryAxis which provide following two extra properties LabelField and ItemsSource that enable user to custom axis label; and thus render the MinorStep property in CategoryAxis useless and is hard-coded to 1.

    You can still accomplish what you want provided you add LabelField/ItemsSouce properties with proper data, but it is much simpler by using Axis.

    For reference, have a look at the source code at : https://github.com/oxyplot/oxyplot/blob/develop/Source/OxyPlot/Axes/CategoryAxis.cs