2

I can remove axes using IsAxisVisible = false like the answers here, but when I do so can no longer pan or zoom the graph.

Example code where the graph doesn't pan (using Oxyplot 2.0):

    public class MainViewModel
    {
        public MainViewModel()
        {
            var tmp = new PlotModel { Title = "Simple example", Subtitle = "using OxyPlot" };

            tmp.Axes.Add(new LinearAxis()
            {
                Position = AxisPosition.Bottom,
                IsAxisVisible = false
            });

            tmp.Axes.Add(new LinearAxis()
            {
                Position = AxisPosition.Left,
                IsAxisVisible = false
            });

            var series1 = new LineSeries { Title = "Series 1", MarkerType = MarkerType.Circle };
            series1.Points.Add(new DataPoint(0, 0));
            series1.Points.Add(new DataPoint(10, 18));
            series1.Points.Add(new DataPoint(20, 12));
            series1.Points.Add(new DataPoint(30, 8));
            series1.Points.Add(new DataPoint(40, 15));

            tmp.Series.Add(series1);

            this.Model = tmp;
        }
        public PlotModel Model { get; private set; }
    }

Edit:

xaml

<Window x:Class="SimpleDemo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf" 
        xmlns:simpleDemo="clr-namespace:SimpleDemo"
        Title="OxyPlot SimpleDemo" Height="480" Width="640">
    <Window.DataContext>
        <simpleDemo:MainViewModel />
    </Window.DataContext>
    <Grid>
        <oxy:PlotView Model="{Binding Model}" />
    </Grid>
</Window>

xaml.cs

    public partial class MainWindow
    {
        public MainWindow()
        {
            this.InitializeComponent();
        }
   }
Siyh
  • 1,747
  • 1
  • 17
  • 24
  • @AnuViswan I can confirm that zooming in doesn't work. Also running the above code with the `IsAxisVisible = false` lines removed allows you to pan at any level of zoom. – Siyh Dec 30 '19 at 09:47
  • Ah ok, good to know it might be something simple! Added Xaml code above. – Siyh Dec 30 '19 at 10:01
  • Out of curiosity, don't see series2 definition. – Anu Viswan Dec 30 '19 at 10:10
  • I simplified some demo code to make the example but missed that reference. Same behaviour with it removed unfortunately. – Siyh Dec 30 '19 at 10:17
  • What's the version of OxyPlot you are using ? 2.0 ? Looks like something has changed from 1.0 to 2.0. Could you please downgrade your oxyplot version to 1.0 and check – Anu Viswan Dec 31 '19 at 00:21
  • You are right, changing to version 1.0 resolves the zoom issue. Unfortunately the downgrade breaks some other features I've implemented though... – Siyh Jan 01 '20 at 10:30

2 Answers2

3

As mentioned in comment earlier, this behavior seems to be happening with Oxyplot 2.0, while 1.0 does allow Zoom/Pan even when the Axis is invisible.

An alternative approach would be to set the AxislineColor,TextColor,and TicklineColor to OxyColors.Transparent.

tmp.Axes.Add(new LinearAxis()
{
    Position = AxisPosition.Bottom,
    IsZoomEnabled = true,
    IsPanEnabled = true,
    AxislineColor = OxyColors.Transparent,
    TextColor = OxyColors.Transparent,
    TicklineColor = OxyColors.Transparent
}); ; ;

tmp.Axes.Add(new LinearAxis()
{
    Position = AxisPosition.Left,
    IsZoomEnabled = true,
    IsPanEnabled = true,
    AxislineColor = OxyColors.Transparent,
    TextColor = OxyColors.Transparent,
    TicklineColor = OxyColors.Transparent
});

This would allow you to Zoom/Pan without displaying the Axis.

Anu Viswan
  • 17,797
  • 2
  • 22
  • 51
  • Thanks Anu. I had tried this but couldn't find a way to remove the space taken up by the invisible axis-do you know if this is possible? – Siyh Jan 01 '20 at 16:05
1

The solution I've settled on (at least until the IsAxisVisible = false issue described in the original question is fixed) is to implement Anu's answer, with the addition of:

Model.PlotMargins = new OxyThickness(0);

To hide the axis thickness.

Siyh
  • 1,747
  • 1
  • 17
  • 24