SciChart Android 2D Charts API > Annotations API > VerticalLineAnnotation

[This article is under construction.]

The VerticalLineAnnotation allows to draw a vertical line between Y1, Y2 coordinates at X1.


VerticalLineAnnotation Features

Please refer to the Common Annotation Features to learn more about the ones inherited from the base class.  The VerticalLineAnnotation class itself allows setting VerticalGravity. More about it in the next paragraph.

Position VerticalLineAnnotation

In general case, the position of an VerticalLineAnnotation can be defined by the X1 value. It can be set via the setX1() method. 

Additionaly, it is possible to specify Y coordinates for the line ends. This requires setting VerticalGravity to a corresponding value via the setVerticalGravity() method. The recognizable values are Gravity.FILL_VERTICALGravity.CENTER_VERTICALGravity.TOPGravity.BOTTOM. In combination with the Y1, Y2 values they will end up in the following behavior:

The Y1, Y2 values can be set via the setY1() or 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 VerticalLineAnnotation

VerticalLineAnnotation 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 VerticalLineAnnotation
VerticalLineAnnotation verticalLine = new VerticalLineAnnotation(getActivity());

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

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

// specify that the annotation should appear fully stretched

// set the X1 coordinate

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

Also, a VerticalLineAnnotation can be created using Chart Builders:

Copy Code
VerticalLineAnnotation verticalLine = sciChartBuilder.newVerticalLineAnnotation()
        .withPosition(5d, 3.2d)
        .withStroke(2, ColorUtil.Orange)

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