oxyplot-avalonia icon indicating copy to clipboard operation
oxyplot-avalonia copied to clipboard

How to add custom axis

Open fizzikzz opened this issue 4 years ago • 1 comments

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?

fizzikzz avatar Nov 10 '21 05:11 fizzikzz

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

VisualMelon avatar Dec 21 '21 17:12 VisualMelon