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