I have a ViewModel class with three controls, two text boxes and a checkbox. The two text boxes are supposed to control minimum and maximum of the chart, and the autoscale should set the AutoRange of the chart.
I’ve got my XAML like this
<sc:SciChartSurface.YAxis>
<sc:NumericAxis AxisTitle="PSD" MaxAutoTicks="5" DrawMinorGridLines="False" AutoRange="{Binding AutoScale}" VisibleRange="{Binding YVisibleRange}">
</sc:NumericAxis>
</sc:SciChartSurface.YAxis>
and in my viewmodel, I have:
public int Maximum
{
get { return _maximum; }
set
{
_maximum = value;
NotifyOfPropertyChange(() => Maximum);
YVisibleRange.Max = _maximum;
}
}
public int Minimum
{
get { return _minimum; }
set
{
_minimum = value;
NotifyOfPropertyChange(() => Minimum);
YVisibleRange.Min = _minimum;
}
}
public DoubleRange YVisibleRange
{
get { return _visibleRange; }
set
{
_visibleRange = value;
NotifyOfPropertyChange(() => YVisibleRange);
}
}
public void ToggleAutoScale()
{
AutoScale = !AutoScale;
}
public bool AutoScale
{
get { return _autoScale; }
set
{
_autoScale = value;
NotifyOfPropertyChange(() => AutoScale);
}
}
The auto scale functionality always works. However, only when I have not used auto scale at all, does the minimum maximum stuff work.
I would like for auto scale to completely control the graph when it’s on, and when it’s off, minimum/maximum should control the range of the graph. How do I achieve this?
- Kasper Hansen asked 11 years ago
- You must login to post comments
Hi there,
I could suggest you binding to whole YAxis instead, because setting AutoRange=”True” override binding on VisibleRange. So you could have something like this:
<s:SciChartSurface ... YAxis="{Binding YAxis, Mode=OneWay, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}"> ..... </s:SciChartSurface>
and in the ViewModel:
public IAxis YAxis { get { return _yAxis; } set { _yAxis = value; NotifyOfPropertyChange(() => YAxis); } }
So this allows you to set VisibleRange every time when AutoScale changes, like this:
public bool AutoScale { get { return _autoScale; } set { _autoScale = value; if(!autoScale) { YAxis.VisibleRange = YVisibleRange; } NotifyOfPropertyChange(() => AutoScale); } }
Does this make sense for you? Please, ask if you have any questions,
Best regards,
Yuriy
- Yuriy Zadereckiy answered 11 years ago
-
BTW, forgot to mention that in this case you should set binding YAxis.AutoRange to AutoScale in code, during axis creation. Hope this helps!
-
I remove the RelativeSource, and it worked! As a side note, is it possible to let the AutoRange update only when there is a value in the graph larger than the current visible range?
-
Hi, Glad you get it working! RelativeSource came from our example from where I got that piece of code :) I'm not sure I understood you correctly, but it seems that you should subscribe to listen to YAxis.VisibleRangeChanged. This allows you to monitor all visible range changes and set the AutoRange correspondingly. Is it what you want to achieve? Best regards, Yuriy
- You must login to post comments
Please login first to submit.