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

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy. We also have a tag=SciChart on Stackoverflow.com where you can earn rep for your questions!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

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
    • 1 year ago
    swarovski korvakorut swarovski outlet swarovski myyntiswarovski korvakorut swarovski outlet swarovski myyntiswarovski 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.