We were recently asked on priority support tickets ‘How do I ZoomExtents a SciChartSurface to a specific range, e.g. VisibleRangeLimit, when double clicking on the chart’.
For the benefit of our user-base our solution is below.
- Andrew Burnett-Thompson asked 10 years ago
- last edited 10 years ago
- You must login to post comments
Note that VisibleRangeLimit API will limit the VisibleRange (e.g. not go beyond it) but it will also not expand the range when the VisibleRangeLimit is outside the data-range. To achieve this, you need a custom ZoomExtentsModifier.
public class CustomZoomExtentsModifier : ChartModifierBase
{
public override void OnModifierDoubleClick(ModifierMouseArgs e)
{
base.OnModifierDoubleClick(e);
ParentSurface.ZoomExtentsToVisibleRangeLimit();
}
}
public static class SciChartSurfaceExtensions
{
public static void ZoomExtentsToVisibleRangeLimit(this ISciChartSurface scs)
{
using (scs.SuspendUpdates())
{
foreach (var axis in scs.YAxes)
{
var range = axis.VisibleRangeLimit ?? axis.GetMaximumRange();
axis.AnimateVisibleRangeTo(range, TimeSpan.FromMilliseconds(500));
}
foreach (var axis in scs.XAxes)
{
var range = axis.VisibleRangeLimit ?? axis.GetMaximumRange();
axis.AnimateVisibleRangeTo(range, TimeSpan.FromMilliseconds(500));
}
}
}
}
Feel free to modify for your needs!
- Andrew Burnett-Thompson answered 10 years ago
- last edited 10 years ago
- You must login to post comments