Articles in this section
Category / Section

How to zoom in and out of a WPF Chart in the scroll viewer?

2 mins read

The article describes how to perform WPF Chart zooming within the scroll viewer using the mouse wheel. To enable zooming through the mouse wheel, set the EnableMouseWheelZooming property of ChartZoomPanBehavior to true.

 

The default behavior is that when the chart is placed inside the scroll viewer, it scrolls up or down instead of zooming in or out. By limiting the scrolling action to the scroll viewer, we can zoom in or out of the chart without any unintended interactions.Default scroll viewer display in WPF ChartThe scrolling action inside the scroll viewer has been restricted according to the following code samples:

[C#]

public class ScrollViewerExt: ScrollViewer
    {
        protected override void OnMouseWheel(MouseWheelEventArgs e)
        {
            // To restrict scroll action on chart
            if (e.Source is SfChart)
                return;
            
            base.OnMouseWheel(e);
        }
    }

[XAML]

<local:ScrollViewerExt VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Hidden" >
        <StackPanel>
            <chart:SfChart  x:Name="chart">
                . . .
                <chart:SfChart.Behaviors >
                    <chart:ChartZoomPanBehavior EnableMouseWheelZooming="True" />
                </chart:SfChart.Behaviors>
                . . .
            </chart:SfChart>
            <chart:SfChart  x:Name="chart1">
                . . .
                <chart:SfChart.Behaviors >
                    <chart:ChartZoomPanBehavior EnableMouseWheelZooming="True" />
                </chart:SfChart.Behaviors>
                . . .
            </chart:SfChart>
 
            <chart:SfChart  x:Name="chart2">
                . . .
                <chart:SfChart.Behaviors >
                    <chart:ChartZoomPanBehavior EnableMouseWheelZooming="True" />
                </chart:SfChart.Behaviors>
                . . .
            </chart:SfChart>
        </StackPanel>
    </local:ScrollViewerExt>

Download the complete sample on GitHub.

Restriced scroll display in WPF ChartRefer also to:

How to improve performance while zooming by using scrollbar in WPF Chart (SfChart)?

How to display the visible range of labels while zooming in WPF Chart (SfChart)?

How to reset zooming in WPF Chart (SfChart)?

 

Conclusion

I hope you enjoyed learning about how to zoom in and out of a WPF Chart in the scroll viewer.

You can refer to our WPF Chart’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WPF Chart documentation to understand how to present and manipulate data.

For current customers, you can check out our WPF components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WPF Chart and other WPF components.

If you have any queries or require clarifications, please let us know in the comment section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied