All Axis Types include the AxisCore.LabelProvider property, which allows a class to be attached to an axis for complete control over axis label output.
Use a LabelProvider when you want to:
- Have fine grained control over Axis Text or Cursor Labels, depending on numeric (or date) values
- Display strings on the XAxis, e.g. “Bananas”, “Oranges”, “Apples” not “1”, “2”, “3”
- Dynamically change the Axis TextFormatting as you zoom in or out
- Dynamically change the Axis TextFormatting depending on Data-value
Creating your own LabelProviders
By default each axis has a LabelProvider created and assigned to it. The type of LabelProvider depends on the type of Axis. Below is a table of the LabelProviders already defined in SciChart Android.
- NumericLabelProvider– used to provide labels on the NumericAxis.
- DateLabelProvider– used to provide labels on the DateAxis.
- LogarithmicNumericLabelProvider - used to provide labels on the LogarithmicNumericAxis.
- TradeChartAxisLabelProvider– used to provide labels on the CategoryDateAxis.
If you create a LabelProvider, inherit from the correct class above, and override formatLabel() and formatCursorLabel() methods.
The former is called internally for every axis tick value to get a text to show for corresponding axis label. Also it is used to format AxisMarkerAnnotation labels. The latter is called to format data values for axis overlays, such as Cursor axis labels.
A LabelProvider can be assigned to an axis via the setLabelProvider() method.
Worked Example: Creating a Custom NumericAxis LabelProvider
To create a custom label provider for the NumericAxis, we simply create a class that inherits NumericLabelProvider, and override formatLabel() and optionally, formatCursorLabel()
To apply a custom label provider, call the setLabelProvider() method on an axis: