SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components
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
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
Please login first to submit.