SciChart WPF 2D Charts > Axis APIs > Axis Ranging - AutoRange and VisibleRange
Axis Ranging - AutoRange and VisibleRange

Axis AutoRanging

The AxisCore.AutoRange property defines how the axis autoranges when data is added.

  • AxisCore.AutoRange = AutoRange.Once (Default Setting)

    The axis will attempt to autorange once to fit the data as you start the chart. This is the default setting. Setting an explicit VisibleRange on the axis will override this behaviour.
  • AxisCore.AutoRange = AutoRange.Always

    The axis will attempt to autorange always to fit the data every time the chart is drawn. This setting will override any programmatic ranging, including zooming and panning by modifiers, but is useful in situations where you always want to view the extents of the data.
  • AxisCore.AutoRange = AutoRange.Never

           The axis will never autorange. Use this to solve issues at startup caused by AutoRange.Once

 

Setting Axis.VisibleRange Programmatically

To programmatically range an axis, set the property AxisCore.VisibleRange with an IRange derived type.

DateTimeAxis

DateTimeAxis
Copy Code
var dateTimeAxis = new DateTimeAxis();
dateTimeAxis.VisibleRange = new DateRange(DateTime.Now, DateTime.Now.AddDays(10));

NumericAxis and LogarithmicNumericAxis

NumericAxis and LogarithmicNumericAxis
Copy Code
var numericAxis = new NumericAxis(); // or LogarithmicNumericAxis
numericAxis.VisibleRange = new DoubleRange(10.0, 100.0);

TimeSpanAxis

TimeSpanAxis
Copy Code
var timespanAxis = new TimeSpanAxis();
timespanAxis.VisibleRange = new TimeSpanRange(TimeSpan.Zero, TimeSpan.FromSeconds(10));

CategoryDateTimeAxis

The CategoryDateTimeAxis is a little different. The VisibleRange defines the indices displayed on the axis, e.g. an IndexRange of 0 to 100 means ‘display data-points with indices 0 to 100 inclusive’.

CategoryDateTimeAxis
Copy Code
var categoryDateTimeAxis = new CategoryDateTimeAxis();
categoryDateTimeAxis.VisibleRange = new IndexRange(0, 100);

Binding to VisibleRange in MVVM

VisibleRange is a DependencyProperty, so you can bind to it. The TwoWay binding is advisable to prevent issues with DependencyProperty Precedence, since we set the VisibleRange property internally in code.

Binding to VisibleRange
Copy Code
<!-- View -->
<s:DateTimeAxis VisibleRange="{Binding XVisibleRange, Mode=TwoWay}"/>

// ViewModel
private IRange _xVisibleRange;
public IRange XVisibleRange
{
   get { return _xVisibleRange; }
   set
   {
       if (_xVisibleRange != value)
          {
              _xVisibleRange = value;
                OnPropertyChanged("XVisibleRange");
          }
   }
} 
See Also