We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Is there a way to zoom out beyond the bounds of data?

Thread ID:

Created:

Updated:

Platform:

Replies:

146923 Aug 26,2019 07:48 AM UTC Aug 29,2019 08:56 AM UTC Xamarin.Forms 1
loading
Tags: SfChart
Fernando Ruiz
Asked On August 26, 2019 07:48 AM UTC

I'm wondering if there is a way to zoom out beyond the bound of data with pinch gesture in a SfChart which has a NumericalAxis as secondary axis and a DateTimeAxis as primary axis.

Muneesh Kumar G [Syncfusion]
Replied On August 29, 2019 08:56 AM UTC

Hi Fernando, 
  
Greetings from Syncfusion.  
 
We have achieved your requirement by changing the Minimum and Maximum values for axis in ZoomDelta event when we zoom beyond the initial range of data. If you want to reset the initial range during double tap means, you can store the axis initial range in ActualRangeChanged event and reset it in ResetZoom event. Please refer the below code. 
  
Code snippet: 
private void DateTimeAxis_ActualRangeChanged(object sender, ActualRangeChangedEventArgs e) 
{ 
    if (isPrimaryLoadTime) 
    { 
        if (Device.RuntimePlatform == Device.UWP) 
        { 
            initialPrimaryMinimum = Convert.ToDateTime(e.ActualMinimum).ToOADate(); 
            initialPrimaryMaximum = Convert.ToDateTime(e.ActualMaximum).ToOADate(); 
        } 
        else 
        { 
            initialPrimaryMinimum = (double)e.ActualMinimum; 
            initialPrimaryMaximum = (double)e.ActualMaximum; 
        } 
  
        isPrimaryLoadTime = false; 
    } 
} 
  
private void NumericalAxis_ActualRangeChanged(object sender, ActualRangeChangedEventArgs e) 
{ 
    if (isSecondaryLoadTime) 
    { 
        initialSecondaryMinimum = (double)e.ActualMinimum; 
        initialSecondaryMaximum = (double)e.ActualMaximum; 
        isSecondaryLoadTime = false; 
    } 
} 
  
private void Chart_ZoomDelta(object sender, Syncfusion.SfChart.XForms.ChartZoomDeltaEventArgs e) 
{ 
    //if you want to zoom beyond DateTimeAxis, you can add this code 
    if (e.Axis is DateTimeAxis) 
    { 
        if (e.PreviousZoomFactor == 1 && e.CurrentZoomFactor == 1) 
        { 
            double interval = 0; 
            if (dateTimeAxis.VisibleLabels.Count > 2) 
            { 
                var data = dateTimeAxis.VisibleLabels; 
                interval = data[1].Position - data[0].Position; 
            } 
  
            dateTimeAxis.Minimum = DateTime.FromOADate(dateTimeAxis.VisibleMinimum - interval); // subtract the value as you want to decrease the range during zoom out 
            dateTimeAxis.Maximum = DateTime.FromOADate(dateTimeAxis.VisibleMaximum + interval); // add the value as you want to increase the range during zoom out 
        } 
    } 
    //if you want to zoom beyond NumericalAxis, you can add this code 
    else if (e.Axis is NumericalAxis) 
    { 
        if (e.PreviousZoomFactor == 1 && e.CurrentZoomFactor == 1) 
        { 
            double interval = 0; 
            if (numericalAxis.VisibleLabels.Count > 2) 
            { 
                var data = numericalAxis.VisibleLabels; 
                interval = data[1].Position - data[0].Position; 
            } 
  
            numericalAxis.Minimum = numericalAxis.VisibleMinimum - interval; 
            numericalAxis.Maximum = numericalAxis.VisibleMaximum + interval; 
        } 
    } 
} 
  
private void Chart_ResetZoom(object sender, ChartResetZoomEventArgs e) 
{ 
    dateTimeAxis.Minimum = DateTime.FromOADate(initialPrimaryMinimum); 
    dateTimeAxis.Maximum = DateTime.FromOADate(initialPrimaryMaximum); 
    numericalAxis.Minimum = initialSecondaryMinimum; 
    numericalAxis.Maximum = initialSecondaryMaximum; 
} 
  
  
Note – You can enable the EnableDirectionalZooming property to zoom the chart based on pinch gesture direction 
  
UG links: 
 
Regards,  
Muneesh Kumar G 
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon