Pre loader

Zooming in real time charts when AutoRange is enabled?

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

Answered
4
0

How do I implement zooming in real time charts. The examples are all static data, and the zooming works, and a couple of links I found, do not explain it very well.

How can I accomplish zooming on a real time SciChart?

  • You must to post comments
Best Answer
5
0

NOTE: RubberBandXyZoomModifier, ZoomPanModifier, MouseWheelZoomModifier, XAxisDragModifier are not compatible with AutoRange.Always. To use AutoRange.Always as well as manual zooming, you will need to temporarily disable AutoRange as you zoom, e.g. on mouse-down disable AutoRange and on mouse double-click re-enable it.

Two ways you could do this:

  1. Handle MouseDown/MouseDoubleClick on the parent SciChartSurface
  2. Do this by creating a class which inherits RubberBandXyZoomModifier and overriding OnModifierMouseDown, OnModifierMouseDoubleClick

For example

public class RubberBandXyZoomModifierEx : RubberBandXyZoomModifier
{
    /// <summary>
    /// When the user does mouse drag & mouse up, stop AutoRange and perform the zoom
    /// </summary>
    public override void OnModifierMouseUp(ModifierMouseArgs e)
    {
        // Disable AutoRange on all axis!
        foreach (var axis in ParentSurface.YAxes)
        {
            axis.AutoRange = AutoRange.Never;
        }
        foreach (var axis in ParentSurface.XAxes)
        {
            axis.AutoRange = AutoRange.Never;
        }

        // Now do the zoom
        base.OnModifierMouseUp(e);
    }

    /// <summary>
    /// When the user double clicks, re-enable zoom and zoom to extents
    /// </summary>
    public override void OnModifierDoubleClick(ModifierMouseArgs e)
    {
        base.OnModifierDoubleClick(e);

        // Reset AutoRange on all axis
        foreach (var axis in ParentSurface.YAxes)
        {
            axis.AutoRange = AutoRange.Always;
        }
        foreach (var axis in ParentSurface.XAxes)
        {
            axis.AutoRange = AutoRange.Always;
        }

        // Now zoom to extents! 
        ParentSurface.ZoomExtents();
    }
}

Update Oct 2014

We now have an documented workaround in the Knowledgebase showing how to mix Zoom, Pan modifiers with AutoRange. This is the technique we use in the Real Time Ticking Stock Charts example to automatically scroll the latest N points, but allow zooming and panning as well.

Best regards,
Andrew

    • Guest
    • 7 years ago
    swarovski korvakorut swarovski outlet swarovski myynti swarovski korvakorut swarovski outlet swarovski myynti swarovski australia swarovski verkossa korvakorut blog korvakorut About blog
  • You must to post comments
0
0

I had the same problem! I’ve implemented a RealTime FIFO Chart which should be zoomable.

Andrew, your RubberBandXyZoomModifierEx was not enough in my case, so i had to modify it a little bit.

/// <summary>
/// Extends the rubber band functionality
/// </summary>
public class RubberBandXyZoomModifierEx : RubberBandXyZoomModifier
{
    /// <summary>
    /// Internal field to a value indicating whether double click was pressed
    /// </summary>
    private bool _isDoubleClickPressed = false;

    /// <summary>
    /// When the user does mouse drag mouse up, stop AutoRange and perform the zoom
    /// </summary>
    /// <param name="e">mouse arguments</param>
    public override void OnModifierMouseUp(ModifierMouseArgs e)
    {
        if (!_isDoubleClickPressed)
        {
            // Disable AutoRange on all axis!
            foreach (var axis in ParentSurface.YAxes)
            {
                axis.AutoRange = AutoRange.Never;
            }

            foreach (var axis in ParentSurface.XAxes)
            {
                axis.AutoRange = AutoRange.Never;
            }
        }
        else
        {
            _isDoubleClickPressed = false;
        }

        // Now do the zoom
        base.OnModifierMouseUp(e);
    }

    /// <summary>
    /// When the user double clicks, re-enable zoom and zoom to extents
    /// </summary>
    /// <param name="e">mouse arguments</param>
    public override void OnModifierDoubleClick(ModifierMouseArgs e)
    {
        base.OnModifierDoubleClick(e);

        _isDoubleClickPressed = true;

        // Now zoom to extents!
        ParentSurface.AnimateZoomExtents(System.TimeSpan.FromMilliseconds(500));

        // Reset AutoRange on all axis
        foreach (var axis in ParentSurface.YAxes)
        {
            axis.AutoRange = AutoRange.Always;
        }

        foreach (var axis in ParentSurface.XAxes)
        {
            axis.AutoRange = AutoRange.Always;
        }
    }
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.