Pre loader

Problems with AutoRange and custom Min/Max via MVVM

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

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(() =&gt; Maximum);
            YVisibleRange.Max = _maximum;
        }
    }


    public int Minimum
    {
        get { return _minimum; }
        set
        {
            _minimum = value;
            NotifyOfPropertyChange(() =&gt; Minimum);
            YVisibleRange.Min = _minimum;
        }
    }

    public DoubleRange YVisibleRange
    {
        get { return _visibleRange; }
        set
        {
            _visibleRange = value;
            NotifyOfPropertyChange(() =&gt; YVisibleRange);
        }
    }


    public void ToggleAutoScale()
    {
        AutoScale = !AutoScale;
    }

    public bool AutoScale
    {
        get { return _autoScale; }
        set
        {
            _autoScale = value;
            NotifyOfPropertyChange(() =&gt; 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?

  • You must to post comments
0
0

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
    BTW, forgot to mention that in this case you should set binding YAxis.AutoRange to AutoScale in code, during axis creation. Hope this helps!
  • Kasper Hansen
    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?
  • Yuriy Zadereckiy
    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 to post comments
Showing 1 result
Your Answer

Please first to submit.

Try SciChart Today

Start a trial and discover why we are the choice
of demanding developers worldwide

Start TrialCase Studies