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

0
0

hi,
How can I add shortcut keys for RubberBandXyZoomModifier and ZoomPanModifier?

When I do Cntl++ my chart should zoom in and when I click right arrow, my chart should pan right.

Thanks in advance,
Vibin

Version
latest
  • You must to post comments
0
0

Hi Vibin,

Something like this will work:

/// <summary>
/// A single X-Y axis implementation of a Zooming In / Out on KeyDown (CTRL+, CTRL-), used to demonstrate the ChartModifierBase and Axis Interactivity APIs in SciChart
/// </summary>
public class SimpleZoomInOutModifier : ChartModifierBase
{
    public static readonly DependencyProperty ZoomFractionProperty = DependencyProperty.Register("ZoomFraction", typeof(double), typeof(SimpleZoomInOutModifier), new PropertyMetadata(0.1));

    public double ZoomFraction
    {
        get { return (double)GetValue(ZoomFractionProperty); }
        set { SetValue(ZoomFractionProperty, value); }
    }

    public override void OnModifierKeyDown(ModifierKeyArgs e)
    {
        base.OnModifierKeyDown(e);

        double factor = 0;

        if ((e.Key == Key.Add || e.Key == Key.OemPlus) && Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
        {
            // On CTRL+, Zoom In
            factor = -ZoomFraction;
        }
        if ((e.Key == Key.Subtract || e.Key == Key.OemMinus) && Keyboard.Modifiers.HasFlag(ModifierKeys.Control))
        {
            // On CTRL-, Zoom Out
            factor = ZoomFraction;
        }

        using (ParentSurface.SuspendUpdates())
        {
            // Zoom the XAxis by the required factor
            XAxis.ZoomBy(factor, factor, TimeSpan.FromMilliseconds(500));

            // Zoom the YAxis by the required factor
            YAxis.ZoomBy(factor, factor, TimeSpan.FromMilliseconds(500));

            // Note.. can be extended for multiple YAxis XAxis, just iterate over all axes on the parent surface
        }
    }
}

Use this custom modifier and attach to your SciChartSurface.ChartModifier property. Then use CTRL ++ to zoom in and CTRL+- to zoom out.

Panning is equally simple. You can use XAxis.Scroll method to programmatically pan.

Best regards,
Andrew

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.