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
A 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 boxAnnotation.setEditable(true); // in a multi-axis scenario, specify the XAxisId and YAxisId boxAnnotation.setXAxisId("Top_X_Axis"); boxAnnotation.setYAxisId("Left_Y_Axis"); // specify a desired position by setting coordinates boxAnnotation.setX1(1d); boxAnnotation.setY1(4.6d); boxAnnotation.setX2(10d); boxAnnotation.setY2(9.1d); // specify the background color for the annotation boxAnnotation1.setBackgroundColor(0x44FF1919); // 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) .withBackgroundDrawableId(R.drawable.example_box_annotation_background_1) .withXAxisId("Top_X_Axis") .withYAxisId("Left_Y_Axis") .withIsEditable(true) .build() |
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.