SciChart Android 2D Charts API > Annotations API > AxisMarkerAnnotation

The AxisMarkerAnnotation type allows to place markers with custom text onto X or Y axes. By default, they show the axis value at their location:


AxisMarkerAnnotation Features

Please refer to the Common Annotation Features to learn more about the ones inherited from the base class. Among those that are specific to AxisMarkerAnnotation, the most important are listed in the table below:

Feature Description
getFormattedValue()setFormattedValue() Allows to specify the text that will apear on the marker.
getFormattedValueProvider() / setFormattedValueProvider()

Allows to override the default formatted value, which comes from an axis via an AxisInfo object. To do this, you need to implement the IFormattedValueProvider interface. The default implementation can be found in the DefaultFormattedValueProvider class.

getFontStyle()setFontStyle() Determines the appearance of the text on the marker via a FontStyle object. Please refer to the Styling and Theming article to learn more.
getMarkerPointWidth()setMarkerPointWidth() Allows to specify the length of the pointed end of the marker.

Position AxisMarkerAnnotation

The position of an AxisMarkerAnnotation is defined by the X1 or Y1 coordinate, depending on axis. It can be set via the setX1() or setY1() methods. 

AxisMarkerAnnotation can be placed on an X axis or an Y axis. This must be specified when an annotation is created via the setAnnotationSurface() method. It accepts a member of the AnnotationSurfaceEnum enumeration.

In a multi-axis scenario, or if you changed the Ids of your axes, both XAxisId and YAxisId must be set. This can be done via the setAxisId(), setYAxisId() methods.

Also, AxisMarkerAnnotation can be aligned relative to the X1 or Y1 coordinate setting Anchor Points. Please refer to the corresponding section of the Common Annotation Features article for more information.

Create AxisMarkerAnnotation

An AxisMarkerAnnotation can be added onto a chart using the following code:

Copy Code
// assume the surface has been created and configured before
ISciChartSurface surface;

// create an AxisMarkerAnnotation
AxisMarkerAnnotation topMarker1 = new AxisMarkerAnnotation(getActivity());

// allow to interact with the marker in run-time

// in a multi-axis scenario, specify the XAxisId and YAxisId

// specify that the marker should appear on an X Axis
// The X Axis is chosen by the XAxisId set above

// set the X1 coordinate, since the marker is going to be located on an X axis

// set the text which will appear on the marker
// by default, shows the axis value at the location
topMarker1.setFormattedValue("X1 Position");

// specify the background color for the marker

// create a FontStyle for the marker
FontStyle markerFont = new FontStyle(14, ColorUtil.White);

// apply the FontStyle

// add the annotation to the Annotations collection of the surface
Collections.addAll(surface.getAnnotations(), topMarker1);

Please note that majority of the values in the code sample above are set for educational purposes. Most of them are optional (such as FontStyle and Background) and inherit their default values from the default style. The ones that must be set are AnnotationsSurface (canvas), X1 or Y1 (position) and XAxisId or YAxisId (in a multi-axis scenario or if axis Ids where set explicitly to specify the axis). To learn more about these, please scroll the page up to the opening paragraphs.

Also, an AxisMarkerAnnotation can be created using Chart Builders:

Copy Code
AxisMarkerAnnotation topMarker1 = sciChartBuilder.newAxisMarkerAnnotation()

To learn more about other annotation types, available out of the box in SciChart, please find the comprehensive list in the What Is an Annotation article.

See Also