SciChart Android 2D Charts API > Annotations API > BoxAnnotation

The BoxAnnotation draws a rectangle at specific X1, X2, Y1, Y2 coordinates:

BoxAnnotation Features

Please refer to the Common Annotation Features to learn more about the ones inherited from the base class. The BoxAnnotation class doesn't define any configurable features on its own. The background color can be assigned via corresponding methods, inherited from View, such as setBackgroundColor() and setBackgroundResource().

Position BoxAnnotation

A BoxAnnotation is placed on a chart at the position determined by its X1,Y1 and X2,Y2 coordinates, which correspond to the top-left and bottom-right corners of the drawn rectangle. It can be set via the setX1(), setY1()setX2()setY2() methods.

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 BoxAnnotation

BoxAnnotation 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 BoxAnnotation
BoxAnnotation boxAnnotation = new BoxAnnotation(getActivity());

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

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

// specify a desired position by setting coordinates

// specify the background color for the annotation

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

Also, BoxAnnotation can be created using Chart Builders:

Copy Code
BoxAnnotation boxAnnotation = sciChartBuilder.newBoxAnnotation()
        .withPosition(3.5d, 4d, 5d, 5d)

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