Pre loader

How to ZoomExtents a SciChartSurface to a specific range, e.g. VisibleRangeLimit, when double clicking on the chart

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 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

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies