Axis APIs
There are several axis types in SciChart Android. Although they all differ in types of data values that can be rendered, the most fundamental difference is in their behavior. By that, the axes can be divided into two groups, Category and Value axis types. Please read the Value Axis vs. Category Axis article elaborating on what the difference is.
A list of the axis types are found below:
Axis Type | Value or Category Axis |
---|---|
NumericAxis | Value Axis |
LogarithmicNumericAxis | Value Axis |
DateAxis | Value Axis |
CategoryDateAxis | Category Axis |
All the axis types in SciChart conforms to the IAxis protocol.
NumericAxis
The NumericAxis is a Value-Axis and is suitable for X and Y Axis when the data type on that axis is numeric (e.g. double, int, long, float, short). It is not suitable for non-numeric data types.
To create and configure a NumericAxis, use the following code:
final NumericAxis axis = new NumericAxis(getContext());
axis.setAxisAlignment(AxisAlignment.Right);
axis.setAutoRange(AutoRange.Once);
axis.setGrowBy(new DoubleRange(0.1, 0.1));
axis.setVisibleRange(new DoubleRange(-45.0, 300.0));
LogarithmicNumericAxis
The LogarithmicNumericAxis is a Value axis which uses non-linear (logarithmic) scale. It is suitable for X and Y Axis when the data is numeric (e.g. double, int, long, float, short). It is not suitable for non-numeric data types.
Note
The LogarithmicNumericAxis cannot render data values less than or equal to zero. Please ensure you append valid data to your DataSeries.
To create and configure a LogarithmicNumericAxis, use the following code:
final LogarithmicNumericAxis axis = new LogarithmicNumericAxis(getContext());
axis.setAxisAlignment(AxisAlignment.Right);
axis.setAutoRange(AutoRange.Once);
axis.setGrowBy(new DoubleRange(0.1, 0.1));
// Specifies how labels appear on the axis
axis.setScientificNotation(ScientificNotation.LogarithmicBase);
axis.setTextFormatting("#.#E+0");
// Specifies the logarithm base for the logarithmic scale of the axis
axis.setLogarithmicBase(10.0);
axis.setVisibleRange(new DoubleRange(0.1, 1000.0));
DateAxis
The DateAxis is a Value axis, which is suitable for X and Y Axis and is designed to work with dates only.
Note
The DateAxis is not suitable for numeric data types.
To create and configure a DateAxis, use the following code:
final DateAxis axis = new DateAxis(getContext());
axis.setAxisAlignment(AxisAlignment.Bottom);
axis.setAutoRange(AutoRange.Once);
axis.setGrowBy(new DoubleRange(0.1, 0.1));
axis.setVisibleRange(new DateRange(dateMin, dateMax));
CategoryDateAxis
The CategoryDateAxis is a Category axis and is suitable for the XAxis only. It is designed to handle a special case when data is discontinuous or contains breaks at regular intervals. Unlike the other axis types, it works with with data indices, not actual data values.
Note
The CategoryDateAxis is not suitable for YAxis or numeric data types.
To create and configure a CategoryDateAxis, use the following code:
final CategoryDateAxis axis = new CategoryDateAxis(getContext());
axis.setAxisAlignment(AxisAlignment.Top);
axis.setAutoRange(AutoRange.Once);
axis.setGrowBy(new DoubleRange(0.1, 0.1));
// Set visibleRange to [min data index, max data index]
axis.setVisibleRange(new DoubleRange(10.0, 50.0));
Note
Note the CategoryDateAxis is treated as a special case. Although it is intended to show Dates, it doesn't allow setting DateRange as VisibleRange. The reason for this is that this axis type works with with data indices, not actual data values. So a DoubleRange should be applied instead, with lower data index as Min and Upper data index as Max.
To learn more about how to convert values from Dates to Indexes and back, please refer to the Convert Pixels to Data Coordinates article.
See the Axis Types in action
Please take a look at the examples from the Android Examples Suite listed below to see these axis types in action: