SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
Hi,
I have several chart panes that share a mouse group and a shared visual range (I inject the shared visual range of type IRange in the constructor of the pane view model). I then set the XAxis visual range to the shared visual range inside each pane view model. However, when I use either of the below approaches outside of the pane view model to adjust the min and max of shared visual range, the Xaxis.VisualRange of each pane does not reflect that change.
Approach A: _sharedVisualRange.Min = ….; _sharedVisualRange.Max = …
Approach B: _sharedVisualRange.SetMinMax(….)
Neither approach actually impacts the XAxis.VisualRange.Min/Max.
Initially when I created the XAxis in code I set its VisualRange equal to the shared visual range that was injected via constructor, like :
XAxis = new CategoryDateTimeAxis()
{
……
……
VisualRange = _sharedVisualRange,
…..
};
Please note that all the above refers to code in the view model. I bind the XAxis in the pane view model to the XAxis of the surface in xaml.
My entire synchronization heavily relies on the assumption of this working, but it does not.
You’re expecting a single IRange instance to be shared across charts. SciChart doesn’t work like that. When you zoom or pan, or when data updates, SciChart itself can create an IRange instance and set on Axis.VisibleRange. This should be shared with other charts via TwoWay Binding to a common property of type IRange.
To update the shared range across all charts, you simply change the instance of the IRange.
This is the approach used in all our examples. Not sure what you’re doing and why but I would suggest to use the reference implementation.
<!-- Chart 1-->
<s:SciChartSurface>
<s:SciChartSurface.XAxis>
<s:CategoryDateTimeAxis VisibleRange="{Binding SharedXRange, Mode=TwoWay}"/>
</s:SciChartSurface.XAxis>
</s:SciChartSurface>
<!-- Chart 2-->
<s:SciChartSurface>
<s:SciChartSurface.XAxis>
<s:CategoryDateTimeAxis VisibleRange="{Binding SharedXRange, Mode=TwoWay}"/>
</s:SciChartSurface.XAxis>
</s:SciChartSurface>
ViewModel
public class ViewModel
{
// To change range on all charts, set this property to new IRange instance
public IRange SharedXRange
{
get => _sharedXRange;
set
{
_sharedXRange = value;
OnPropertyChanged("SharedXRange");
}
}
}
Please login first to submit.