Android & Xamarin.Android Charting Documentation - SciChart Android Charts SDK v2.x
Axis Labels - LabelProvider API

The easiest way to control appearence of axis labels is using text formatting. For more advanced scenarios, a LabelProvider class can be attached to an axis, which allows complete control over text output of any axis label.

Use this approach when you want to:

 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.

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.

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()

Copy Code
public static class NumericLabelProviderEx extends NumericLabelProvider{
    String axisLabelFormat;

    public NumericLabelProviderEx(String axisLabelFormat) {
        super();

        this.axisLabelFormat = axisLabelFormat;
    }

    @Override
    public String formatLabel(Comparable dataValue) {
        // return a formatting string for tick labels
        return String.format(axisLabelFormat, (Double)dataValue);
    }

    @Override
    public String formatCursorLabel(Comparable dataValue) {
        // return a formatting string for modifiers' axis labels
        return formatLabel(dataValue);
    }
}

 

Please note that other axis types require different base types.

To apply a custom label provider, call the setLabelProvider() method on an axis:

Copy Code
IAxis axis = new NumericAxis(getActivity());

// create a NumericLabelProviderEx with a specific formatting
// and assign it to the axis
axis.setLabelProvider(new NumericLabelProviderEx("%+,8f"));

 

See Also