SciChart Android 2D Charts API > Annotations API > TextAnnotation

The TextAnnotation allows to place a piece of text at a specific location on a chart:

TextAnnotation Features

Please refer to the Common Annotation Features to learn more about the ones inherited from the base class. The features that are specific to the TextAnnotation type can be found in the table below:

getFontStyle()setFontStyle() Allows to specify how text should appear via a FontStyle object.  Please refer to the Styling and Theming section to learn more about styles in SciChart.
getText() / setText() Specifies the text for an annotation.
getTextGravity()setTextGravity() Specifies a text alignment with Android Gravity.
getCanEditText()setCanEditText() When set to True, allows to modify the text in run-time after selecting an annotation.
getRotationAngle()setRotationAngle() Rotates an annotation through the specified angle in degrees.

Position TextAnnotation

The position of an TextAnnotation is defined by the X1,Y1 values. These can be set via the setX1() or setY1() methods. 

Also, a TextAnnotation can be aligned relative to its X1,Y1 position via Anchor Points. Please refer to the corresponding section of the Common Annotation Features article for more information.

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.

Create TextAnnotation

TextAnnotation can be added onto a chart using the following code:

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

// create a TextAnnotation
TextAnnotation textAnnotation = new TextAnnotation(getActivity());

// specify a FontStyle for the text
textAnnotation.setFontStyle(new FontStyle(30f, 0x66FC9C29));

// set the text
textAnnotation.setText("My Text Annotation");

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

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

// specify anchor points

// specify a desired position by setting coordinates

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

Also, a TextAnnotation can be created using Chart Builders:

Copy Code
TextAnnotation textAnnotation = sciChartBuilder.newTextAnnotation()
        .withText("My Text Annotation")
        .withPosition(7.5d, 5d)
        .withFontStyle(12, ColorUtil.White)

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