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 the ZoomExtents Range

By default, a ZoomExtents operation (for example double-clicking the chart when the ZoomExtentsModifier is enabled, or calling SciChartSurface.ZoomExtents()) fits each axis to its data. Set AxisBase.ZoomExtentsRange to make ZoomExtents return to an explicit range instead:

<s:NumericAxis ZoomExtentsRange="0, 100" />

xAxis.ZoomExtentsRange = new DoubleRange(0, 100);

When ZoomExtentsRange is set to a valid range, every ZoomExtents operation on that axis brings this range; when it is null or invalid, ZoomExtents falls back to the default fit-to-data behavior. The property is also exposed on the axis ViewModels for MVVM, and if a VisibleRangeLimit is set as well, the limit is applied to the ZoomExtentsRange.

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