Zooming a ScatterGraph in Measurement Studio Without Keyboard Modifiers

Updated May 5, 2026

Reported In

Software

  • Measurement Studio
  • Microsoft Visual Studio

Issue Details

I am using VB.NET with Measurement Studio and the NationalInstruments.UI.WindowsForms.ScatterGraph control.

I would like to know if there is a built-in setting that allows zooming without using the keyboard, using only the mouse, such as mouse clicks or the mouse wheel.

Solution

There is no single built-in property that changes the ScatterGraph zoom behavior to mouse-wheel zoom around the pointer location. However, this behavior can be implemented by handling the MouseWheel event manually.

The application should use the mouse pointer position as the zoom anchor. To do this, the mouse position must be converted from pixel coordinates to graph axis values. Then, the application can calculate the new X and Y axis ranges around that location.

Imports NationalInstruments.UI

Private Sub ScatterGraph1_MouseEnter(sender As Object, e As EventArgs) Handles ScatterGraph1.MouseEnter

    ' Ensure the graph receives MouseWheel events when the mouse is over it.
    ScatterGraph1.Focus()

End Sub

Private Sub ScatterGraph1_MouseWheel(sender As Object, e As MouseEventArgs) Handles ScatterGraph1.MouseWheel

    Dim xAxis = ScatterGraph1.XAxes(0)
    Dim yAxis = ScatterGraph1.YAxes(0)

    Dim xRange As Range = xAxis.Range
    Dim yRange As Range = yAxis.Range

    ' Get the plot area in pixel coordinates.
    Dim plotArea As Rectangle = ScatterGraph1.PlotAreaBounds

    ' Do not zoom if the mouse pointer is outside the plot area.
    If Not plotArea.Contains(e.Location) Then
        Return
    End If

    ' Convert the mouse position from pixels to a relative position inside the plot area.
    Dim mouseXRatio As Double = (e.X - plotArea.Left) / CDbl(plotArea.Width)
    Dim mouseYRatio As Double = (e.Y - plotArea.Top) / CDbl(plotArea.Height)

    ' Convert the mouse position from plot-area pixels to axis values.
    Dim mouseXValue As Double =
        xRange.Minimum + mouseXRatio * (xRange.Maximum - xRange.Minimum)

    ' The Y pixel coordinate increases from top to bottom.
    ' The graph Y axis usually increases from bottom to top.
    Dim mouseYValue As Double =
        yRange.Maximum - mouseYRatio * (yRange.Maximum - yRange.Minimum)

    ' Define the zoom factor.
    ' Mouse wheel up: zoom in.
    ' Mouse wheel down: zoom out.
    Dim zoomFactor As Double = If(e.Delta > 0, 0.8, 1.25)

    ' Calculate the new X range while keeping the mouse X value as the zoom anchor.
    Dim newXMin As Double =
        mouseXValue - ((mouseXValue - xRange.Minimum) * zoomFactor)

    Dim newXMax As Double =
        mouseXValue + ((xRange.Maximum - mouseXValue) * zoomFactor)

    ' Calculate the new Y range while keeping the mouse Y value as the zoom anchor.
    Dim newYMin As Double =
        mouseYValue - ((mouseYValue - yRange.Minimum) * zoomFactor)

    Dim newYMax As Double =
        mouseYValue + ((yRange.Maximum - mouseYValue) * zoomFactor)

    ' Apply the new ranges.
    xAxis.Range = New Range(newXMin, newXMax)
    yAxis.Range = New Range(newYMin, newYMax)

End Sub

 

This implementation allows the application to zoom into the area under the mouse pointer instead of always zooming into the center of the graph.