UWP- double tap zoom out doesnt work

When i click double tap on andorid it zooms in and another double tap, zooms out.
I try the same action on UWP, zoom in works but zoom out wont work. below is my implementation of sfchart


                <chart:SfChart x:Name="Chart" SelectionChanged="Chart_SelectionChanged" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"  
                        >              
                    <chart:SfChart.PrimaryAxis>

                        <chart:DateTimeCategoryAxis AutoScrollingDelta="7"   AutoScrollingMode="End"  >

                            <chart:DateTimeCategoryAxis.Title>

                                <chart:ChartAxisTitle Text="{resx:Translate Date}"></chart:ChartAxisTitle>

                            </chart:DateTimeCategoryAxis.Title>

                        </chart:DateTimeCategoryAxis>

                    </chart:SfChart.PrimaryAxis>

                    <chart:SfChart.SecondaryAxis>

                        <chart:NumericalAxis  Minimum="0" Maximum="{Binding NumericalAxisMax}" Interval="{Binding NumericalAxisInterval}" >

                            <chart:NumericalAxis.Title>

                                <chart:ChartAxisTitle Text="{Binding NumericalAxisTitle}" ></chart:ChartAxisTitle>

                            </chart:NumericalAxis.Title>

                        </chart:NumericalAxis>

                    </chart:SfChart.SecondaryAxis>

                    <chart:SfChart.Series>

                        <chart:LineSeries EnableDataPointSelection="{Binding EnableDataPointSelection}"  XBindingPath="XValue" YBindingPath="YValue" 
                                  SelectedDataPointColor="Yellow"  ItemsSource="{Binding NumericMonthStats, Mode=OneWay}"  EnableAnimation = "true"
                                  AnimationDuration="0.8" >
                            <chart:LineSeries.DataMarker>
                                <chart:ChartDataMarker/>
                            </chart:LineSeries.DataMarker>
                        </chart:LineSeries>

                    </chart:SfChart.Series>
                    <chart:SfChart.ChartBehaviors>

                        <chart:ChartZoomPanBehavior x:Name="ZoomBehavior"  ZoomMode="X"/>

                    </chart:SfChart.ChartBehaviors>

                </chart:SfChart>


1 Reply

BK Bharathiraja K Syncfusion Team April 23, 2019 11:03 AM UTC

Hi Emil, 
 
We have prepared the custom solution to achieve zoom in and zoom out by inheriting ChartZoomPanBehavior as a workaround for UWP. 
 
Please find the code snippet below. 
 
Note: Add below codes only for UWP. 
[C#] 
    public class CustomZoomPanBehavior: ChartZoomPanBehavior 
    { 
        protected override void DoubleTap(float pointX, float pointY) 
        { 
            if (Device.RuntimePlatform == Device.UWP) 
            { 
                if (EnableDoubleTap && !EnableSelectionZooming) 
                { 
                    var axis = Chart.PrimaryAxis; 
                    if (axis.ZoomFactor == 1 && axis.ZoomPosition == 0) 
                    { 
                        var seriesBound = Chart.SeriesBounds; 
                        var manipulationX = pointX - seriesBound.Left - Chart.ChartPadding.Left; 
                        var manipulationY = pointY - seriesBound.Top - Chart.ChartPadding.Top; 
 
                        var origin = GetOrigin(manipulationX, manipulationY, seriesBound.Width, seriesBound.Height, axis); 
 
                        Zoom(axis, 2.5f, origin); 
                    } 
                    else 
                    { 
                        Reset(); 
                    } 
                } 
            } 
            else 
            { 
                base.DoubleTap(pointX, pointY); 
            } 
        } 
 
        private static float GetOrigin(double manipulationX, double manipulationY, double width, double height, ChartAxis chartAxis) 
        { 
            float origin; 
            if (!chartAxis.IsVertical) 
            { 
                origin = (float)(chartAxis.IsInversed 
                    ? 1.0 - ((manipulationX - chartAxis.PlotOffset) / width) 
                    : (manipulationX - chartAxis.PlotOffset) / width); 
            } 
            else 
            { 
                origin = (float)(chartAxis.IsInversed 
                    ? (manipulationY - chartAxis.PlotOffset) / height 
                    : 1 - ((manipulationY - chartAxis.PlotOffset) / height)); 
            } 
 
            return origin; 
        } 
    } 
 
 
   <chart:SfChart.ChartBehaviors> 
            <local:CustomZoomPanBehavior ZoomMode="X"/> 
   </chart:SfChart.ChartBehaviors> 
 
And we have prepared the sample, that can be downloaded from below link. 
 
 
Regards, 
Bharathi. 


Loader.
Up arrow icon