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

Hi,

There are some methods exposed in the API, ZoomBy and ZoomExtent which can programmatically be called from the code behind.
I am binding the series using IRenderableSeriesViewModel in MVVM pattern. Can we zoom the sciChart surface on a button click in ModelView?

Appreciating your help on this.

Thanks

Version
4.2.2.9777
  • You must to post comments
0
0

Hi Anil

You can control the SciChartSurface directly from the ViewModel by following this technique:

ViewportManager – Full Control over Axis Ranges and Viewport

You can call the following functions on a ViewportManager from a ViewModel. Use these to have direct control over the SciChartSurface in absence of a SciChartSurface instance itself.

Assuming you have bound a ViewportManager as per Declaring a Binding to a ViewportManager in MVVM

public class MyViewModel : INotifyPropertyChanged
{
    // Viewmodel
       private DefaultViewportManager _viewportManager = new DefaultViewportManager();
       public IViewportManager ViewportManager
       {
          get { return _viewportManager; }
          set
          {
               _viewportManager = value;
               OnPropertyChanged("ViewportManager");
          }
       }

       public void Foo()
       {
             // All things you can do from the ViewModel with a ViewportManager
             // We don't recommend doing them all at once! :)
             _viewportManager.ZoomExtents();
              _viewportManager.AnimateZoomExtents(TimeSpan.FromMilliseconds(500));
             _viewportManager.ZoomExtentsY();
             _viewportManager.AnimateZoomExtentsY(TimeSpan.FromMilliseconds(500));
             _viewportManager.ZoomExtentsX();
             _viewportManager.AnimateZoomExtentsX(TimeSpan.FromMilliseconds(500));
       }
}

Note that there may be a short delay between setting data and being able to zoom to extents on it. This is because of the delay in binding in WPF itself.

In order to work around this delay, we recommend a technique like this:

            // Invoke AnimateZoomExtents after binding engine has stabilised 
            _viewportManager.BeginInvoke(() =>
            {
                var duration = TimeSpan.FromMilliseconds(250);
                _viewportManager.AnimateZoomExtents(duration);                    
            });

Best regards,
Andrew

  • Anil Prasad
    Thanks Andrew, the zoomextent works perfectly. But I could not see the ZoomBy method in the viewportmanager interface. What I have written in the code behind file is: // TODO: Need to implement zoom using MVVM private void BtnZoomIn_Click(object sender, RoutedEventArgs e) { TemperatureGraph.ChartModifier.XAxis.ZoomBy(-0.1, -0.1); } I want to perform the same in the ViewModel Class. Please help! Regards, Anil
  • Andrew
    ZoomBy is unfortunately an API on the Axis itself. It is not available on the ViewportManager. If you want to call this function in an MVVM fashion you will need to use WPF Behaviors or think of a way to call a View methods from the ViewModel. http://stackoverflow.com/questions/19847860/how-to-call-method-in-window-xaml-cs-from-viewmodel-cs-without-introducing
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.