How to limit pinch-and-zoom in Xamarin

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Robert L.
Newbie
Newbie
Posts: 2
Joined: Wed Jan 25, 2017 12:00 am

How to limit pinch-and-zoom in Xamarin

Post by Robert L. » Tue Feb 14, 2017 3:01 pm

We have a chart with a logaritmic scale. We would like to limit the smallest and the largest value for each axis, i.e. not letting the user scroll or zoom to see values smaller than 0.1 or larger than 10,000,000 (Our logaritmic base is 10).

We have managed to limit scrolling by listening to the Chart.Scroll event and manually setting the Axis.Minium or Axis.Maximum if the user scoll past the limits. But trying to do the same thing with pinch-n-zoom doesn't work since the Chart.Zoomed event isn't raised until the user lift their fingers.

Is there a way to either set limits on the axes themselves or only allow zooming in from default view (showing a subset of what was originally displayed) but not zooming out (showing more than was originally displayed)?

Pep
Site Admin
Site Admin
Posts: 3173
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Re: How to limit pinch-and-zoom in Xamarin

Post by Pep » Wed Feb 15, 2017 11:30 am

Hello Robert,
which TeeChart Xamarin version are you using (Xamarin.Forms, Xamarin.iOS or Xamarin.Android) ?

Robert L.
Newbie
Newbie
Posts: 2
Joined: Wed Jan 25, 2017 12:00 am

Re: How to limit pinch-and-zoom in Xamarin

Post by Robert L. » Mon Feb 20, 2017 12:35 pm

We're using Xamarin.Forms and are targeting both Android and iOS.

Pep
Site Admin
Site Admin
Posts: 3173
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Re: How to limit pinch-and-zoom in Xamarin

Post by Pep » Mon Feb 20, 2017 3:00 pm

Hello Robert,

we've already added a new OnPinch event for Xamarin.Forms. It'll be available for the next maintenance release which will be published very soon.
But, in meantime you could use the OnBeforeDrawAxes event in order to check the minimum and maximum axis values and force a setMinMax for axis.
Here the code :

Code: Select all

       tChart1.BeforeDrawAxes += TChart1_BeforeDrawAxes;

        private void TChart1_BeforeDrawAxes(object sender, Steema.TeeChart.Drawing.Graphics3D g)
        {
            if (tChart1.Axes.Bottom.Minimum < 0)
            {
                tChart1.Axes.Bottom.SetMinMax(line.XValues.MinValue,line.XValues.MaxValue);
                tChart1.Draw();
            }
            else
                tChart1.Axes.Bottom.Automatic = true;
        }

Post Reply