SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components

Answered
0
0

I want to zoom the chart using mouse wheel. But not zoom at mouse point center, but at the specified point center I set.

How can I do it?
Is there any properties for MouseWheelZoomModifier?

Version
v5.1.1.11473
  • You must to post comments
Best Answer
1
1

Hi there

You can override MouseWheelZoomModifier.OnModifierMouseWheel() to customize the behaviour

For example

    /// <summary>
    /// Called when the Mouse Wheel is scrolled on the parent <see cref="SciChartSurface"/>
    /// </summary>
    /// <param name="e">Arguments detailing the mouse wheel operation</param>
    /// <remarks></remarks>
    public override void OnModifierMouseWheel(ModifierMouseArgs e)
    {
        base.OnModifierMouseWheel(e);

        e.Handled = true;

        const double mouseWheelDeltaCoef = 120;

        using (ParentSurface.SuspendUpdates())
        {
            double value = -e.Delta / mouseWheelDeltaCoef;

            var currDirection = XyDirection;
            var currAction = ActionType;

            OverrideKeyboardAction(e.Modifier);

           // THIS is where we get the mouse point
            var mousePoint = GetPointRelativeTo(e.MousePoint, ModifierSurface);
            _performAction(mousePoint, value);

            TryStoreRangesToZoomHistoryManager();

            this.SetCurrentValue(XyDirectionProperty, currDirection);
            this.SetCurrentValue(ActionTypeProperty, currAction);
    }

Or … the much simpler way – to pass a different point to the base

    public class MouseWheelModifierEx : MouseWheelZoomModifier
    {
        public override void OnModifierMouseWheel(ModifierMouseArgs e)
        {
            // Override the mouse point
            e.MousePoint = new Point(10, 20);

            // Call base
            base.OnModifierMouseWheel(e);
        }
    }

Best regards,
Andrew

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.

SciChart WPF v6 BETA released! Note pricing/licensing changes are coming. Contact us to beat the rise!Read more
+