Pre loader

Key Board Short Cut Keys for Zoom and Pan

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

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.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies