oxyplot / oxyplot-avalonia

A cross-platform plotting library for .NET. This package targets Avalonia apps.
https://oxyplot.github.io/
MIT License
274 stars 47 forks source link

How to add custom axis #39

Open fizzikzz opened 3 years ago

fizzikzz commented 3 years ago

If I make a custom axis using an OxyPlot.LinearAxis as the base class like:

public class CustomLinearAxis : LinearAxis { }

The background on my usercontrol hosting the PlotView that uses the custom axis turns black. It seems like it doesn't style properly.

Is there a way to add custom axes in OxyPlot-Avalonia properly?

VisualMelon commented 2 years ago

I can't reproduce a black screen using an empty override like you describe, though OxyPlot.LinearAxis doesn't exist; you need either OxyPlot.Axes.LinearAxis or OxyPlot.Avalonia.LinearAxis: the former is the normal linear-axis model, the latter you can use in XAML bindings and all that.

For example, here you could add an instance of CustomLinearAxis to PlotModel.Axes, or include a CustomAxis in Plot.Axes (e.g. in XAML):

public class CustomAxis : OxyPlot.Avalonia.LinearAxis
{
    public CustomAxis()
    {
        InternalAxis = new CustomLinearAxis();
    }
}

public class CustomLinearAxis : LinearAxis
{
    public override void GetTickValues(out IList<double> majorLabelValues, out IList<double> majorTickValues, out IList<double> minorTickValues)
    {
        base.GetTickValues(out majorLabelValues, out majorTickValues, out minorTickValues);
        minorTickValues.Clear();
    }
}