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

Pan and Zoom not working

Open Nuada26 opened this issue 8 years ago • 6 comments
trafficstars

Hi all,

I have a problem with my plotview in Xamarin forms, i see it but when i try to pan or zomm on it, it's not work.

This is my code in C#:

        var model = new PlotModel { Title = "Hello, Forms!", PlotAreaBorderColor = OxyColors.Transparent };

        var BottomAxis = new TimeSpanAxis();
        BottomAxis.Position = AxisPosition.Bottom;
        model.PlotAreaBorderThickness = new OxyThickness(0, 0, 0, 0);
        BottomAxis.IntervalLength = TimeSpanAxis.ToDouble(new TimeSpan(1,0,0));

        var LeftAxis = new LinearAxis();
        LeftAxis.Position = AxisPosition.Left;
        LeftAxis.Minimum = 0d;
        LeftAxis.Maximum = 50d;
        var myController = new PlotController();
        plotview.Controller = myController;
        
        model.Axes.Add(LeftAxis);
        model.Axes.Add(BottomAxis);

        var Serie = new LineSeries();
        Serie.Points.Add(new DataPoint(TimeSpanAxis.ToDouble(DateTime.Now.TimeOfDay.Subtract(new TimeSpan(0, 0, 20))),10d ));
        Serie.Points.Add(new DataPoint(TimeSpanAxis.ToDouble(DateTime.Now.TimeOfDay.Subtract(new TimeSpan(0, 3, 20))),55d ));
        Serie.Points.Add(new DataPoint(TimeSpanAxis.ToDouble(DateTime.Now.TimeOfDay.Subtract(new TimeSpan(0, 4, 20))),15d ));

        model.Series.Add(Serie);
        plotview.Model = model;

And this is View on XAML:

<oxy:PlotView x:Name="plotview" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="3"/>

Any idea for resolve that?

Thanks in advance

Nuada26 avatar Jun 27 '17 07:06 Nuada26

I also had the same problem. I debugged the ExampleBrowser running on iOS and I tracked the problem down to 2 issues with OxyPlot.Core.

Number 1

The constructor for PlotController installs 2 TouchDown bindings, the first is for handling Pan/Zoom and the second is for handling a tracker. Well, in the constructor, you will see multiple items being bound to the same event, however, those allow multiple bindings per event as long as the modifier is different. A modifier would be like which keyboard key or which mouse button. However, touch is touch with no modifier. This means the second binding for TouchDown (for the tracker) OVERWRITES the first binding for TouchDown (panning/zooming). So the first fix is to comment out the second tracker binding.

Number 2

Even after fixing problem number 1 above, panning/zooming on touch devices still doesn't work. This is because the Tracker touch manipulator extends the touch manipulator but the touch manipulator does NOT default the panning/zooming support to true. So the fix is to add a line to the constructor of TouchManipulator to set SetHandledForPanOrZoom = true;

scastria avatar Jan 21 '18 22:01 scastria

@scastria I came across the same issues with Windows.Forms. But I also noticed, that Number 2 is fixed with https://github.com/oxyplot/oxyplot/issues/1184

Currently, I'm working on a fix for Number 1. As soon as I got my pull request ready, I'll attach it here.

rapmue avatar May 08 '18 13:05 rapmue

Hello! Is there an update on this issue? I'm using OxyPlot.Core and OxyPlot.Xamarin.Android NuGets which are re-installed on 5/10/2018. I can't zoom the graphs using code. Touch zoom works properly.

Anax7 avatar Oct 08 '18 08:10 Anax7

Hello Is there an update or an ETA on this topic? I am using Oxyplot for Xamarin.Forms and not being able to zoom or pan the charts is unfortunately a breaking issue for me.

Setomba avatar Jan 15 '20 09:01 Setomba

I don´t know the status on this issue. We depend on contributions to get this fixed! (I recommend to include oxyplot-xamarin as source code (e.g. by using git submodule), not as nuget package, to make sure you get the latest version)

objorke avatar Feb 26 '20 19:02 objorke

I work with WPF, touch and pan was not working out of the box, with a little research I found that SnapTrackTouch is causing this issue. Binding to my own controller and unbinding all TouchDown commands from it, fixed touch input. I just had to bind PanZoomByTouch again:

var plotcontroller = new PlotController();
plotcontroller.UnbindTouchDown();
plotcontroller.BindTouchDown(PlotCommands.PanZoomByTouch);

In fact, both SnapTrackTouch and PanZoomByTouch work fine separately but not together. Snap track in my opinion could be disabled by default, it's not useful on a touch screen, the point tooltip is only visible for a split second. Or am I wrong and it can be used for other things as well?

Enduteri avatar Nov 02 '23 17:11 Enduteri