SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & 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.

0
0

I’m using a number of modifiers to allow the user to pan and zoom, including a ZoomExtentsModifier so the user can double-click to “reset” the chart back to its initial layout. However it seems to ignore the VisibleRanges I’ve got on the axes. How can I get it to honour these?

Here is an example of one of my axes, just in case one of its attributes is preventing the modifier from working properly:-

<SciChart:NumericAxis AxisAlignment="Left" AutoRange="False" DrawMajorTicks="False" DrawMinorTicks="False" VisibleRange="{Binding YAxisRange, Mode=TwoWay}" DrawMinorGridLines="False" DrawLabels="True" AxisTitle="Foo"/>

(I seem to remember being told a while ago that the VisibleRange binding must be TwoWay otherwise it won’t work. Is that correct?)

Thanks in advance
Andy

  • You must to post comments
0
0

Hi there,

As I understand, you want to perform zoom extents to initial ranges. ZoomExtentsModifier performs it to extents of data instead. What I can suggest you is to rise an event after zoom extents performed and set VisibleRanges to desired ranges in a handler. Please, take a look at Zoom including annotations thread, there is the example how to achieve it. in this case you should bind ChartModifier to ViewModel, create modifiers and handle the event there.

Please, feel free to ask if you need further assistance – we are glad to help!

Best regards,
Yuriy

  • andyste1
    Hi Yuriy, thanks for the reply. I've created a custom ZoomExtentsModifier as per your link, but I'm not sure what code to put in the "OnUserZoomExtents" event handler to apply the required VisibleRanges. I've tried refreshing the bindings like this:- BindingOperations.GetBindingExpression(XAxis, NumericAxis.VisibleRangeProperty).UpdateTarget(); BindingOperations.GetBindingExpression(YAxis, NumericAxis.VisibleRangeProperty).UpdateTarget(); The event handler is getting called after the chart has zoomed out to the extents of data, but the above code has no effect, i.e. it isn't readjusting the chart extents based on the VisibleRanges. What am I doing wrong?
  • You must to post comments
0
0

Hi again,

I thought a bit and found better solution for your case. We don’t need to inherit from ZoomExtentsModifier (because we need to override its behavior completely), so lets create own modifier:

    public class CustomZoomExtentsModifier : ChartModifierBase
    {
        IRange InitialXRange
        { get; set; }

        TimeSpan Duration
        { get; set; }

        public CustomZoomExtentsModifier()
        {
            ExecuteOn = ExecuteOn.MouseDoubleClick;
            Duration = TimeSpan.FromMilliseconds(500);

            // Can be set in XAML
            InitialXRange = new DoubleRange(-10, 10);
        }

        public override void OnModifierDoubleClick(ModifierMouseArgs e)
        {
            XAxis.AnimateVisibleRangeTo(InitialXRange, Duration);

            // Animate Y VisibleRange to extents on given X range (includes GrowBy)
            ParentSurface.ZoomExtentsY(InitialXRange, Duration);

            // or
            // YAxis.AnimateVisibleRangeTo(InitialYRange, Duration);
        }
    }

Please, let us know if this helps!

Best regards,
Yuriy

  • andyste1
    That helped me to find a solution, thanks. I now take a copy of the VisibleRanges when the VM first creates the chart data, then in the event handler of my custom zoom extents modifier (the original one, not your second suggestion) I use AnimateVisibleRangeTo() to action the change:- XAxis.AnimateVisibleRangeTo(_viewModel.OriginalXAxisRange, new TimeSpan(0, 0, 1)); YAxis.AnimateVisibleRangeTo(_viewModel.OriginalYAxisRange, new TimeSpan(0, 0, 1)); Am I right in saying that VisibleRange must use TwoWay binding? What's the reason for this? If it supported OneWay then the solution would have been simpler - I wouldn't need to take a copy of the original values, and could probably have just updated the binding using .UpdateTarget() as in my earlier post.
  • Yuriy
    Hi, I'm glad you've solved it! This requirement to use TwoWay binding is mandatory if you are going to interact with a chart(use modifiers, for example). Basically, most of visible range changes are performed as axis.VisibleRange=[newVisibleRange] internally, and this overrides every binding except TwoWay. If you are aware of SetCurrentValue(...) method, we cannot use it, because it doesn't exist in Silverlight and there seems not to be any workaround, but we want to keep the source code working in same way for both WPF and SL. Best regards, Yuriy
  • You must to post comments
0
0

Is there any update to handle it in an easy way?
Tried to make a custom ViewportManager, but the example under following link didn’t work https://www.scichart.com/questions/question/zoom-including-annotations/#post-3504.
I just wanna zoom back to the VisibleRange i have set in the YAxis.

  • Andreas Graf
    Okay I solved it. I saw that I have to assign GrowBy to the YAxis. Now it works all fine.
  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.