SciChart Android 2D Charts API > Annotations API > What Is an Annotation
What Is an Annotation

SciChart features a rich Annotations API, that allows you to place Android Views over a chart:

Annotation Features

Annotations can provide interactive event/news bullets, horizontal/vertical lines (thresholds), text/callouts as well as measurements such as Peak-to-peak or cycle duration. Annotations can be edited by click & drag, added by touching a screen, or, simply created programmatically. SciChat provides a number of built-in annotations, but you can also create your own. To find out more about annotations features, please see the Common Annotations Features article.

Annotation Types

The following annotation types are available out of the box in SciChart:

Type Description
AxisMarkerAnnotation Allows to place markers with custom text onto X, Y axes. By default, shows the axis value at its location.
BoxAnnotation Draws a rectangle at specific X1, X2, Y1, Y2 coordinates.
HorizontalLineAnnotation Draws a horizontal line between X1, X2 coordinates at Y1.
VerticalLineAnnotation Draws a vertical line between Y1, Y2 coordinates at X1.
LineAnnotation Draws a line between X1, Y1 and X2, Y2 positions.
LineArrowAnnotation Draws an arrow from X1, Y1 to X2, Y2 position.
TextAnnotation Allows to place a piece of text at a specific location on a chart.
CustomAnnotation Allows to place any Android View at a specific location on a chart.

To learn more about any annotation type, please refer to the corresponding article.

Adding an Annotation Onto a Chart

SciChartSurface stores all its annotations in the internal AnnotationCollection. It exposes the getAnnotations() and setAnnotations() methods to access it. The following code can be used to do this:

Copy Code
// Assume the surface has been created and configured earlier
ISciChartSurface surface;

// Create and configure a HorizontalLineAnnotation
HorizontalLineAnnotation horizontalLineAnnotation = new HorizontalLineAnnotation(getActivity());
horizontalLineAnnotation.setStroke(new PenStyle(ColorUtil.Orange, false, 2f));

// Add the annotation to the AnnotationsCollection of a surface
Collections.addAll(surface.getAnnotations(), horizontalLineAnnotation);

Also Annotations can be added using Chart Builders:

Copy Code
// Create a watermark using a TextAnnotation
TextAnnotation textAnnotation = sciChartBuilder.newTextAnnotation()
        .withFontStyle(Typeface.DEFAULT_BOLD, 42, 0x22FFFFFF)
        .withText("Create \n Watermarks")

// Add the annotation to the AnnotationsCollection of a surface
Collections.addAll(surface.getAnnotations(), textAnnotation);


See Also