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

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
    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
    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.