The AxisMarkerAnnotation
The AxisMarkerAnnotation type allows to place markers with custom text onto X or Y axes. They show the axis value at their location by default:
Note
Examples of the Annotations usage can be found in the SciChart Android Examples Suite as well as on GitHub:
The AxisMarkerAnnotation can be configured using the properties listed in the table below:
Feature | Description |
---|---|
setFormattedValue(CharSequence formattedValue) | Allows to specify the text that will appear on the marker. |
setFormattedValueProvider(IFormattedValueProvider formattedValueProvider) | Allows to override the default formatted value, which comes from an axis via an AxisInfo object. Please refer to the AxisMarkerAnnotation TextFormatting section to learn more. |
setFontStyle(FontStyle fontStyle) | Determines the appearance of the text on the marker via the FontStyle object. Please refer to the Styling and Theming article to learn more. |
setMarkerPointWidth(int markerPointWidth) | Allows to specify the length of the pointed end of the marker. |
Note
To learn more about other Annotation Types, available out of the box in SciChart, please find the comprehensive list in the Annotation APIs article.
The AxisMarkerAnnotation can be placed on the X-Axis or the Y-Axis which is specified via the annotationSurface property. It accepts a member of the AnnotationSurfaceEnum enumeration and it defaults to XAxis for the AxisMarkerAnnotation.
Position of the AxisMarkerAnnotation is defined by the X1
or Y1
coordinate, depending on the axis.
Those values can be accessed via the x1 and y1 properties.
Also, AxisMarkerAnnotation can be aligned relative to the X1
or Y1
coordinate by setting Anchor Points.
For more information about the Anchor Points - refer to the corresponding section Annotations APIs article.
Note
The xAxisId and yAxisId must be supplied if you have axis with non-default Axis Ids, e.g. in multi-axis scenario.
Create an AxisMarkerAnnotation
A simple AxisMarkerAnnotation can be added onto a chart using the following code:
// Assume a surface has been created and configured somewhere
// Create an AxisMarkerAnnotation
final AxisMarkerAnnotation rightMarker = new AxisMarkerAnnotation(getContext());
// Specify a desired position by setting the Y1 coordinate, since the marker is going to be located on an Y axis
rightMarker.setY1(8);
// Allow to interact with the annotation in run-time
rightMarker.setIsEditable(true);
// In a multi-axis scenario, specify the XAxisId and YAxisId
rightMarker.setXAxisId("BottomAxisId");
rightMarker.setYAxisId("RightAxisId");
// Specify the background color for the marker
rightMarker.setBackgroundColor(0xAA4083B7);
// Add the annotation to the Annotations collection of the surface
surface.getAnnotations().add(rightMarker);
AxisMarkerAnnotation TextFormatting
By default, the axis marker text is formatted by the textFormatting property. For more information, refer to the Axis Labels - TextFormatting and CursorTextFormatting article.
But you can also override the default behaviour by using textformatting by providing custom the IFormattedValueProvider for your AxisMarkerAnnotation corresponding property.
Let's see a short example which shows how to use the above:
// Declare custom IFormattedValueProvider
class AnnotationValueProvider implements IFormattedValueProvider {
@Override
public CharSequence formatValue(AxisInfo axisInfo) {
return axisInfo != null ? String.format("[ --- %s --- ]", axisInfo.axisFormattedDataValue) : null;
}
}
// Provide custom IFormattedValueProvider for the annotation
rightMarker.setFormattedValueProvider(new AnnotationValueProvider());
which will result in the following:
Note
To learn more about other Annotation Types, available out of the box in SciChart, please find the comprehensive list in the Annotation APIs article.