SciChart Android 2D Charts API > Axis APIs > Axis Labels - LabelProvider API
Axis Labels - LabelProvider API

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.

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:

public static class NumericLabelProviderEx extends NumericLabelProvider{
     String axisLabelFormat;
    public NumericLabelProviderEx(String axisLabelFormat) {
        this.axisLabelFormat = axisLabelFormat;
     public String formatLabel(Comparable dataValue) {
        // return a formatting string for tick labels
         return String.format(axisLabelFormat, (Double)dataValue);
     public String formatCursorLabel(Comparable dataValue) {
        // return a formatting string for modifiers' axis labels
         return formatLabel(dataValue);

// Usage in example - application of custom labelprovider to an axis 
IAxis axis = new NumericAxis(getActivity());
// create a NumericLabelProviderEx with a specific formatting
// and assign it to the axis
axis.setLabelProvider(new NumericLabelProviderEx("%+,8f"));


Please note that other axis types require different base types for the LabelProvider.
See Also