SciChart Android 2D Charts API > Annotations API > LineAnnotation

The LineAnnotation draws a line connecting the X1,Y1 and X2,Y2 positions:

LineAnnotation Features

Please refer to the Common Annotation Features to learn more about the ones inherited from the base class. The Stroke color can be applied via the setStroke() method, which expects a PenStyle object. Please refer to the Styling and Theming section to learn more about pens and brushes in SciChart.

Position LineAnnotation

LineAnnotation is placed on a chart at the position determined by its X1,Y1 and X2,Y2 coordinates, which specify the two line ends. 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 LineAnnotation

LineAnnotation 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 LineAnnotation
LineAnnotation lineAnnotation = new LineAnnotation(getActivity());

// specify a PenStyle for the Stroke
lineAnnotation.setStroke(new SolidPenStyle(0xFF0000FF, true, 4, null));

// 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

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

Also, a LineAnnotation can be created using Chart Builders:

Copy Code
LineAnnotation lineAnnotation = sciChartBuilder.newLineAnnotation()
        .withPosition(1d, 4d, 2d, 6d)
        .withStroke(2f, 0xFF555555)

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