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?
- darlon asked 11 years ago
- last edited 10 years ago
- You must login to post comments
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:
- Handle MouseDown/MouseDoubleClick on the parent SciChartSurface
- 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
- Andrew Burnett-Thompson answered 11 years ago
- last edited 10 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 login to post comments
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;
}
}
- butcher90 answered 7 years ago
- You must login to post comments
Please login first to submit.