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

Answered Closed
0
0

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.

  • You must to post comments
Best Answer
0
0

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!

  • You must to post comments
Showing 1 result