Axis Ranging - Restricting VisibleRange
Clipping the Axis VisibleRange on Zoom and Pan using the VisibleRangeLimit
Given a chart with data in the range of
[0, 10], when you zoom to extents, the axis will have a VisibleRange of
[0, 10]. Sometimes this is not desirable, and you want to clip the
ISCIAxisCore.visibleRange inside the data-range.
To do this, you can use the
For example. Given an axis without any limits (
ISCIAxisCore.visibleRangeLimit = nil). When we perform ZoomExtents on the chart, the
XAxis gets the visible range
So let’s set
After setting such
VisibleRangeLimit and using ZoomExtents we now get an
XAxis.visibleRange = [4.5, 5.5]. In other words, zooming has clipped or limited the visibleRange to
NOTE: VisibleRangeLimit expects a minimum and maximum value according to the
Sometimes it is required to have one end of VisibleRange fixed or restrict VisibleRange either by
ISCIRange.max value. For that purposes, Axis API exposes
SCIRangeClipMode. It allows to specify
ISCIAxisCore.visibleRangeLimitMode property to choose a behavior which is best suitable for a particular scenario.
SCIRangeClipMode.SCIRangeClipMode_MinMax– (Default) allows clipping at Min and Max.
SCIRangeClipMode.SCIRangeClipMode_Max- allows clipping only at Max.
SCIRangeClipMode.SCIRangeClipMode_Min- allows clipping only at Min.
Use this property if you wish to ensure that one side of the chart is always clipped, while the other side is not. For instance:
Results in a chart that always sets
axis.visibleRange.min = 0 when you zoom to extents.
NOTE: VisibleRangeLimit does not clip data range when VisibleRangeLimit is greater than data range. In this case after ZoomExtents you’ll get the actual data range.
Advanced VisibleRange Clipping
ISCIAxisCore.visibleRangeLimit is a useful API to ensure the axis clips the visibleRange when zooming to extents. However, it will not stop a user from scrolling outside of that range. To achieve that, you will need to clip the visibleRange in code.
To clip the
ISCIAxisCore.visibleRange and force a certain maximum or minimum, just use the following code:
Minimum or Maximum Zoom Level
If you want to constrain zoom depth in your application, the
ISCIAxisCore.minimalZoomConstrain allows you to specify the minimal difference between
Max values of axis VisibleRange. If the difference becomes less than MinimalZoomConstrain value - then VisibleRange will not change.
It is also possible to specify the
ISCIAxisCore.maximumZoomConstrain which defines the maximal difference between
Max values of axis VisibleRange. If the difference becomes more than MaximumZoomConstrain value - then VisibleRange will not change.
Read on to learn how to apply Minimum or Maximum Zoom Level for different Axis Types.
Specifying ZoomConstrains for SCINumericAxis
In the following code we are going to specify the visibleRange for
SCINumericAxis. It should never become
less than 10 and
greater than 100. In other words - always be in range of
Specifying ZoomConstrains for SCICategoryDateAxis
ZoomConstrains works differently if set on
SCICategoryDateAxis. It determines the min/max zoom level on an axis which is possible to show by the specifying the amount of data points.
In the code above, VisibleRange should show
no less than 10 data points as well as
no more that 100 data points.
Specifying ZoomConstrains for SCIDateAxis
SCIDateAxis has its specifics as well. It’s VisibleRange is of
SCIDateRange type, so the Zoom Constraints is designed to specify the difference between two dates in seconds. Setting Zoom Constraints on a SCIDateRange, you ensure that your
axis.visibleRange.diff will never become less than the
ISCIAxisCore.minimalZoomConstrain value and more than
NOTE: For convenience, SciChart provides a bunch of helper methods in the
In the code above, the VisibleRange will satisfy the following equation:
2 months < VisibleRange < 10 month