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

Hi, I’m trying to just create a simple WPF MVVM application that binds to the ViewportManager and add series dynamically. The data range (X and Y) will vary and I’d like to zoom to fit after a new series is added. Seems simple, but I cannot get it to work. I’ve tried calling ZoomExtents on a bound DefaultViewportManager as well as InvalidateElement() and InvalidateParentSurface(RangeMode.ZoomToFit) and they all have no affect. I was assuming I was doing something wrong, but if you try the WPF demo/sample application it does the same thing. If you go to 2D Charts -> MVVM Examples -> Manipulate Series MVVM, there is a call to AnimateZoomExtents that doesn’t work either after you add a series. You still have to double click on the graph after clicking the plus button to make it fit the graph. I just want to zoom to fit the data and not use code behind. The functionality is clearly there because if you define <s:ZoomExtentsModifier ExecuteOn="MouseDoubleClick"/> it works perfectly, so how do I force that to happen from my view model? Thank you!

Version
Current
  • You must to post comments
Best Answer
1
0

Hi Andy,

Can you try this code from ViewModel (assuming you have a ViewportManager in your ViewModel bound to SciChartSurface.ViewportManager)

           _viewportManager.BeginInvoke(() =>
            {
                bool isZoomExtendsAnimated = true;
                var duration = isZoomExtendsAnimated ? TimeSpan.FromMilliseconds(250) : TimeSpan.FromMilliseconds(0);
                _viewportManager.AnimateZoomExtents(duration);                    
            });

This should invoke a ZoomExtents on your chart. You can change your data then call this code immediately afterwards and it should theoretically update

Best regards,
Andrew

  • You must to post comments
0
0

Awesome, that worked. Just to verify, simply doing

            _viewportManager.BeginInvoke(() => { _viewportManager.ZoomExtents(); });

works as well if you never want to animate. I’m guessing this has to do with the fact that just doing:

_viewportManager.ZoomExtents();

from the view model, attempts to modify the graph on a non UI thread and throws an exception? Will I need to follow this pattern for other calls to the Viewport Manager from my view model?

You might want to update your sample code! I was struggling over this one for a while. If it is the UI thread I would also suggest not eating the error…had I gotten an exception on the direct .ZoomExtents() call I would have been able to figure out the problem pretty quickly.

Again, thank you for your prompt help..in evaluation mode and this certainly helps!

  • Andrew
    No its because when you simply call ZoomExtents after changing your data, WPF might not have propagated the data changes to the View as these are processed by the Dispatcher at DispatcherPriority.DataBind level. Hence the beginInvoke schedules the Viewport to ZoomExtents *after* the data has updated.
  • Andy None
    That makes sense. Thank you!
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.