Pre loader

How to zoom using button click for better precision

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

Dear all,

Actually in all chart demo the zoom is done by using the mouse and define the area to zoom in.

I would like to be able to have a button when I click on it it will zoom the view port area with a predifine zoom increment.

Question :
How can we control the zoom from a button click without specifying an area but use a zoom increment instead ?

thanks sample

regards

Version
4
  • You must to post comments
0
0

Sure you can, you can zoom programmatically with SciChart WPF.

Please see the article Programmatically Zoom, Scroll an Axis for more information

Example

A simple example below shows how you can use Axis.Zoom() in combination with the ChartModifierBase API to create a simple custom modifier which handles KeyDown and zooms in and out on CTRL+ or CTRL- Key Presses.

Include this on your chart like any other modifier, by setting SciChartSurface.ChartModifier = new SimpleZoomInOutModifier();

/// <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); }
    }

    void SciChart_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        double factor = 0;

        if (e.Key == Key.Add && (Keyboard.Modifiers & ModifierKeys.Control) > 0)
        {
            // On CTRL+, Zoom In
            factor = -ZoomFraction;
        }
        if (e.Key == Key.Subtract && (Keyboard.Modifiers & ModifierKeys.Control) > 0)
        {
            // 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
        }
    }

    public override void OnAttached()
    {
        base.OnAttached();
        var scichart = ((SciChartSurface)ParentSurface);

        var mainWindow = FindLogicalParent<Window>(scichart);

        mainWindow.PreviewKeyDown -= SciChart_PreviewKeyDown;
        mainWindow.PreviewKeyDown += SciChart_PreviewKeyDown;
    }

    private T FindLogicalParent<T>(SciChartSurface scichart) where T:class
    {
        var parent = (FrameworkElement)scichart.Parent;
        while (parent != null)
        {
            var candidate = parent as T;
            if (candidate != null) return candidate;

            parent = (FrameworkElement)parent.Parent;
        }

        return null;
    }
} 

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