Search Results for

    Show / Hide Table of Contents

    The LineAnnotation

    The LineAnnotation draws a line connecting the [X1, X2] and [Y1, Y2] coordinates:

    Line Annotation

    Note

    Examples of the Annotations usage can be found in the SciChart Android Examples Suite as well as on GitHub:

    • Native Android Chart Annotations Example

    • Native Android Chart Interactive Annotations Example

    • Xamarin Android Chart Annotations Example

    • Xamarin Android Chart Interactive Annotations Example

    The LineAnnotation class provides the stroke property which is used to define the line annotation color. It expects a PenStyle object. To learn more about Pens and Brushes and how to utilize them, please refer to the PenStyle, BrushStyle and FontStyle article.

    Note

    To learn more about Annotations in general - please see the Common Annotation Features article.

    A LineAnnotation is placed on a chart at the position determined by its [X1, Y1] and [X2, Y2] coordinates, which specifies the two line ends. Those can be accessed via the following properties: x1, y1, x2, y2

    Note

    The xAxisId and yAxisId must be supplied if you have an axis with non-default Axis Ids, e.g. in multi-axis scenario.

    Create a LineAnnotation

    A LineAnnotation can be added onto a chart using the following code:

    • Java
    • Java with Builders API
    • Kotlin
    // Assume a surface has been created and configured somewhere
    // Create a Line Annotation
    final LineAnnotation lineAnnotation = new LineAnnotation(getContext());
    
    // Allow to interact with the annotation in run-time
    lineAnnotation.setIsEditable(true);
    
    // In a multi-axis scenario, specify the XAxisId and YAxisId
    lineAnnotation.setXAxisId("TopAxisId");
    lineAnnotation.setYAxisId("LeftAxisId");
    
    // Specify a desired position by setting coordinates
    lineAnnotation.setCoordinateMode(AnnotationCoordinateMode.RelativeY);
    lineAnnotation.setX1(20);
    lineAnnotation.setY1(0.2);
    lineAnnotation.setX2(60);
    lineAnnotation.setY2(0.8);
    
    // Specify the stroke color for the annotation
    lineAnnotation.setStroke(new SolidPenStyle(0x9942AD42, true, 4f, null));
    
    // Add the annotation to the Annotations collection of the surface
    surface.getAnnotations().add(lineAnnotation);
    
    // Assume a surface has been created and configured somewhere
    // Create a Line Annotation
    final LineAnnotation lineAnnotation = sciChartBuilder.newLineAnnotation()
            // Allow to interact with the annotation in run-time
            .withIsEditable(true)
            // In a multi-axis scenario, specify the XAxisId and YAxisId
            .withXAxisId("TopAxisId")
            .withYAxisId("LeftAxisId")
            // Specify a desired position by setting coordinates
            .withCoordinateMode(AnnotationCoordinateMode.RelativeY)
            .withPosition(20, 0.2, 60, 0.8)
            // Specify the thickness and the stroke color for the annotation
            .withStroke(4f, 0x9942AD42)
            .build();
    
    // Add the annotation to the Annotations collection of the surface
    surface.getAnnotations().add(lineAnnotation);
    
    // Assume a surface has been created and configured somewhere
    // Create a Line Annotation
    val lineAnnotation = LineAnnotation(context)
    
    // Allow to interact with the annotation in run-time
    lineAnnotation.setIsEditable(true)
    
    // In a multi-axis scenario, specify the XAxisId and YAxisId
    lineAnnotation.xAxisId = "TopAxisId"
    lineAnnotation.yAxisId = "LeftAxisId"
    
    // Specify a desired position by setting coordinates
    lineAnnotation.coordinateMode = AnnotationCoordinateMode.RelativeY
    lineAnnotation.x1 = 20
    lineAnnotation.y1 = 0.2
    lineAnnotation.x2 = 60
    lineAnnotation.y2 = 0.8
    
    // Specify the stroke color for the annotation
    lineAnnotation.stroke = SolidPenStyle(-0x66bd52be, true, 4f, null)
    
    // Add the annotation to the Annotations collection of the surface
    surface.annotations.add(lineAnnotation)
    
    Note

    To learn more about other Annotation Types, available out of the box in SciChart, please find the comprehensive list in the Annotation APIs article.

    Back to top © 2011-2025 SciChart. All rights reserved. | sitemap.xml