how to enable zooming in Microsoft chart control by using Mouse wheel

I am using Microsoft Chart control in my project and I want to enable zooming feature in Chart Control by using Mouse Wheel, how can I achieve this?

but user don't have to click on chart, It should be like if mouse position is on my Chart than from that point onward by mouse wheel rolling it can zoom in / out

You'll want to use the MouseWheel event.

First make both axes of your chart zoomable:

chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas[0].AxisY.ScaleView.Zoomable = true;

And assign the event:

chart1.MouseWheel += chart1_MouseWheel;

Then in the event handler:

private void chart1_MouseWheel(object sender, MouseEventArgs e)
{
    var chart = (Chart)sender;
    var xAxis = chart.ChartAreas[0].AxisX;
    var yAxis = chart.ChartAreas[0].AxisY;

    try
    {
        if (e.Delta < 0) // Scrolled down.
        {
            xAxis.ScaleView.ZoomReset();
            yAxis.ScaleView.ZoomReset();
        }
        else if (e.Delta > 0) // Scrolled up.
        {
            var xMin = xAxis.ScaleView.ViewMinimum;
            var xMax = xAxis.ScaleView.ViewMaximum;
            var yMin = yAxis.ScaleView.ViewMinimum;
            var yMax = yAxis.ScaleView.ViewMaximum;

            var posXStart = xAxis.PixelPositionToValue(e.Location.X) - (xMax - xMin) / 4;
            var posXFinish = xAxis.PixelPositionToValue(e.Location.X) + (xMax - xMin) / 4;
            var posYStart = yAxis.PixelPositionToValue(e.Location.Y) - (yMax - yMin) / 4;
            var posYFinish = yAxis.PixelPositionToValue(e.Location.Y) + (yMax - yMin) / 4;

            xAxis.ScaleView.Zoom(posXStart, posXFinish);
            yAxis.ScaleView.Zoom(posYStart, posYFinish);
        }
    }
    catch { }            
}

The e.Delta property tells you how many wheel "scrolls" you've done, and can be useful. Scrolling out at all will zoom out the whole way.

There's probably a cleaner way of doing this, but there it is. Hope this helps!

Zoom and Scroll in 2D XY-Charts | WinForms Controls, Use API to Scroll a Chart; Customize Scroll Bar Appearance; Specify Keyboard Shortcuts and Mouse Actions. Expanded Collapsed Allow Users to Zoom a Chart. how to enable zooming in Microsoft chart control by using Mouse wheel (2) I modificated code from above and added a reverse zooming. So when you rotate a mouse wheel back the chart zoom out. Also i don't recommend use 2^n as divider of the interval because it cause lag.

I modificated code from above and added a reverse zooming. So when you rotate a mouse wheel back the chart zoom out. Also i don't recommend use 2^n as divider of the interval because it cause lag.

numberOfZoom - counter of Zooming
private void Chart1_MouseWheel(object sender, MouseEventArgs e)
    {
        var chart = (Chart)sender;
        var xAxis = chart.ChartAreas[0].AxisX;
        var yAxis = chart.ChartAreas[0].AxisY;

        var xMin = xAxis.ScaleView.ViewMinimum;
        var xMax = xAxis.ScaleView.ViewMaximum;
        var yMin = yAxis.ScaleView.ViewMinimum;
        var yMax = yAxis.ScaleView.ViewMaximum;

        int IntervalX = 3;
        int IntervalY = 3;
        try
        {
            if (e.Delta < 0 && numberOfZoom > 0) // Scrolled down.
            {
                var posXStart = xAxis.PixelPositionToValue(e.Location.X) - IntervalX *2/ Math.Pow(2, numberOfZoom);
                var posXFinish = xAxis.PixelPositionToValue(e.Location.X) + IntervalX *2/ Math.Pow(2, numberOfZoom);
                var posYStart = yAxis.PixelPositionToValue(e.Location.Y) - IntervalY*2 / Math.Pow(2, numberOfZoom);
                var posYFinish = yAxis.PixelPositionToValue(e.Location.Y) + IntervalY*2 / Math.Pow(2, numberOfZoom);

                if (posXStart < 0) posXStart = 0;
                if (posYStart < 0) posYStart = 0;
                if (posYFinish > yAxis.Maximum) posYFinish = yAxis.Maximum;
                if (posXFinish > xAxis.Maximum) posYFinish = xAxis.Maximum;
                xAxis.ScaleView.Zoom(posXStart, posXFinish);
                yAxis.ScaleView.Zoom(posYStart, posYFinish);
                numberOfZoom--;
            }else if (e.Delta < 0 && numberOfZoom == 0) //Last scrolled dowm
            {
                yAxis.ScaleView.ZoomReset();
                xAxis.ScaleView.ZoomReset();
            }
            else if (e.Delta > 0) // Scrolled up.
            {

                var posXStart = xAxis.PixelPositionToValue(e.Location.X) - IntervalX  / Math.Pow(2, numberOfZoom);
                var posXFinish = xAxis.PixelPositionToValue(e.Location.X) + IntervalX / Math.Pow(2, numberOfZoom);
                var posYStart = yAxis.PixelPositionToValue(e.Location.Y) - IntervalY  / Math.Pow(2, numberOfZoom);
                var posYFinish = yAxis.PixelPositionToValue(e.Location.Y) + IntervalY  / Math.Pow(2, numberOfZoom);

                xAxis.ScaleView.Zoom(posXStart, posXFinish);
                yAxis.ScaleView.Zoom(posYStart, posYFinish);
                numberOfZoom++;
            }

            if (numberOfZoom < 0) numberOfZoom = 0;
        }
        catch { }
    }

Scroll and Zoom Feature of Chart for C# WinForms Template Project, And when users need to zoom in and zoom out the chart area, they can use the Ctrl key and Mouse Wheel to control the zoom factor. The pan and scroll  To enable zoom with the mouse wheel in the Photos app in Windows 10, do the following. Open Photos. Its tile is pinned to the Start menu by default. Click the three dots menu button in the top right corner. Click on the Settings menu item. Settings will be opened. Go to "Viewing and editing". Under Mouse Wheel, enable the option Zoom in and out.

Waaaay late to the party, but I had this challenge myself today. I am sure the following can be improved, still, but it's what I came up with. I tested this with .net 4.5.2 and 4.6, so I am not sure if it works with older frameworks.

I've combined a couple of answers from way in the past and made the following:

using System;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace ExampleApp
{
    public partial class Form1 : Form
    {
        private const float CZoomScale = 4f;
        private int FZoomLevel = 0;

        public Form1()
        {
            InitializeComponent();
            chart1.MouseWheel += Chart1_MouseWheel;
        }

        private void Chart1_MouseEnter(object sender, EventArgs e)
        {
            if (!chart1.Focused)
                chart1.Focus();
        }

        private void Chart1_MouseLeave(object sender, EventArgs e)
        {
            if (chart1.Focused)
                chart1.Parent.Focus();
        }

        private void Chart1_MouseWheel(object sender, MouseEventArgs e)
        {
            try {
                Axis xAxis = chart1.ChartAreas[0].AxisX;
                double xMin = xAxis.ScaleView.ViewMinimum;
                double xMax = xAxis.ScaleView.ViewMaximum;
                double xPixelPos = xAxis.PixelPositionToValue(e.Location.X);

                if (e.Delta < 0 && FZoomLevel > 0) {
                    // Scrolled down, meaning zoom out
                    if (--FZoomLevel <= 0) {
                        FZoomLevel = 0;
                        xAxis.ScaleView.ZoomReset();
                    } else {
                        double xStartPos = Math.Max(xPixelPos - (xPixelPos - xMin) * CZoomScale, 0);
                        double xEndPos = Math.Min(xStartPos + (xMax - xMin) * CZoomScale, xAxis.Maximum);
                        xAxis.ScaleView.Zoom(xStartPos, xEndPos);
                    }
                } else if (e.Delta > 0) {
                    // Scrolled up, meaning zoom in
                    double xStartPos = Math.Max(xPixelPos - (xPixelPos - xMin) / CZoomScale, 0);
                    double xEndPos = Math.Min(xStartPos + (xMax - xMin) / CZoomScale, xAxis.Maximum);
                    xAxis.ScaleView.Zoom(xStartPos, xEndPos);
                    FZoomLevel++;
                }
            } catch { }
        }
    }
}

XY Zooming and Scrolling (Windows), In addition to using mouse click and drag, this example demonstrates using a slider, the mouse wheel and a WinViewPortControl to control scrolling and zooming. In the chart, the x-axis and y-axis are configured to synchronize with the view port setWidth(2); // The default ChartDirector settings has a denser y-​axis grid  Enable Zoom in and Out Mouse Wheel in Windows 10 In hindi 2018

How do I enable scrolling / zooming for the Chart?, Essential Chart supports zooming along the X and Y axes. Zooming is implemented by displaying scrollbars with the zoomed portion alone  I am using Microsoft Chart control in my project and I want to enable zooming feature in Chart Control by using Mouse Wheel, how can I achieve this? but user don't have to click on chart, It should be like if mouse position is on my Chart than from that point onward by mouse wheel rolling it can zoom in / out

https://social.msdn.microsoft.com/Forums/vstudio/e, Scrolling and Zooming functionality is not available when using 3D charts. For end-user zooming to be enabled along an axis, the relevant cursor object's This AxisScrollBar class controls the appearance of scrollbars, setting such things as When calling the Scroll method, the developer has the option of scrolling to a  After you manage to get inside the Properties for Synaptics screen, select the Pinch Zoom section from the left pane, then move to the right pane and untick the box associated with Enable Pinch Zoom. Disabling Pinch Zoom from the Synaptics tool menu. Restart your computer and see if the issue is resolved at the next system startup.

Scrolling And Zooming, It is very simple to use and allows users to zoom in the chart plot area when are there The PanZoomMode property allow developers to restrict zooming. The zoom factor can be controlled using Ctrl+MouseWheel for zoom in and zoom out​  When handling the MouseWheel event it is important to follow the user interface (UI) standards associated with the mouse wheel. The MouseEventArgs.Delta property value indicates the amount the mouse wheel has been moved. The UI should scroll when the accumulated delta is plus or minus 120.

Comments
  • This doesn't work for me. The Chart's Mousewheel event isn't firing.
  • Apparently, you have to do this first for it to work void friendChart_MouseLeave(object sender, EventArgs e) { if (friendChart.Focused) friendChart.Parent.Focus(); } void friendChart_MouseEnter(object sender, EventArgs e) { if (!friendChart.Focused) friendChart.Focus(); } Mousewheel event not firing
  • Just saw this; funny thing is that you linked to one of my questions :) Glad you got it working.
  • Works grate but, how to zoom also the background image?
  • It's been a while since I looked at this, but just assign xAxis.ScaleView.ZoomReset(); yAxis.ScaleView.ZoomReset(); to a button click event?
  • what is numberofZoom
  • it counter which count amount of changing position of mouse wheel. It is integer varaible.
  • How to initialize it?
  • Your answer is missing the definition of CZoomScale
  • Thanks for notifying, fixed it. :)