Search Results for

    Show / Hide Table of Contents

    The AxisLabelAnnotation

    The AxisLabelAnnotation allows to place a piece of text at a specific location on an Axis:

    Axis Label 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

    Since AxisLabelAnnotation is nearly the same as TextAnnotation, hence everything about configuring it is the same. Please see the TextAnnotation article to learn more.

    The only difference is that AxisLabelAnnotation can be placed on the X-Axis or the Y-Axis instead of the Chart Surface. That's is specified via the annotationSurface property. It accepts a member of the AnnotationSurfaceEnum enumeration and it defaults to XAxis for the AxisMarkerAnnotation.

    Position of the AxisMarkerAnnotation is defined by the X1 or Y1 coordinate, depending on the axis. Those values can be accessed via the x1 and y1 properties.

    Note

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

    Create a AxisLabelAnnotation

    A AxisLabelAnnotation 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 CustomAnnotation instance
    AxisLabelAnnotation axisLabelAnnotation = new AxisLabelAnnotation(getContext());
    
    // Set the text
    axisLabelAnnotation.setText("Axis Label can be Rotated");
    
    // Specify a FontStyle for the text
    axisLabelAnnotation.setFontStyle(new FontStyle(20, 0xFFFF1919));
    
    // Specify rotation Angle in Degrees if needed
    axisLabelAnnotation.setRotationAngle(-30);
    
    // Specify a desired position by setting the X1 coordinate, since the marker is going to be located on an X axis
    axisLabelAnnotation.setX1(60);
    
    // Specify the desired Axis to place annotation on via AnnotationSurface
    axisLabelAnnotation.setAnnotationSurface(AnnotationSurfaceEnum.XAxis);
    
    // Allow to interact with the annotation in run-time
    axisLabelAnnotation.setIsEditable(true);
    
    // In a multi-axis scenario, specify the XAxisId and YAxisId
    axisLabelAnnotation.setXAxisId("BottomAxisId");
    axisLabelAnnotation.setYAxisId("LeftAxisId");
    
    // Add the annotation to the Annotations collection of the surface
    surface.getAnnotations().add(axisLabelAnnotation);
    
    // Assume a surface has been created and configured somewhere
    // Create CustomAnnotation instance
    AxisLabelAnnotation axisLabelAnnotation = new AxisLabelAnnotation(getContext());
    
    // Set the text
    axisLabelAnnotation.setText("Axis Label can be Rotated");
    
    // Specify a FontStyle for the text
    axisLabelAnnotation.setFontStyle(new FontStyle(20, 0xFFFF1919));
    
    // Specify rotation Angle in Degrees if needed
    axisLabelAnnotation.setRotationAngle(-30);
    
    // Specify a desired position by setting the X1 coordinate, since the marker is going to be located on an X axis
    axisLabelAnnotation.setX1(60);
    
    // Specify the desired Axis to place annotation on via AnnotationSurface
    axisLabelAnnotation.setAnnotationSurface(AnnotationSurfaceEnum.XAxis);
    
    // Allow to interact with the annotation in run-time
    axisLabelAnnotation.setIsEditable(true);
    
    // In a multi-axis scenario, specify the XAxisId and YAxisId
    axisLabelAnnotation.setXAxisId("BottomAxisId");
    axisLabelAnnotation.setYAxisId("LeftAxisId");
    
    // Add the annotation to the Annotations collection of the surface
    surface.getAnnotations().add(axisLabelAnnotation);
    
    // Assume a surface has been created and configured somewhere
    // Create CustomAnnotation instance
    val axisLabelAnnotation = AxisLabelAnnotation(context)
    
    // Set the text
    axisLabelAnnotation.text = "Axis Label can be Rotated"
    
    // Specify a FontStyle for the text
    axisLabelAnnotation.fontStyle = FontStyle(20.0f, -0xe6e7)
    
    // Specify rotation Angle in Degrees if needed
    axisLabelAnnotation.rotationAngle = -30f
    
    // Specify a desired position by setting the X1 coordinate, since the marker is going to be located on an X axis
    axisLabelAnnotation.x1 = 60
    
    // Specify the desired Axis to place annotation on via AnnotationSurface
    axisLabelAnnotation.annotationSurface = AnnotationSurfaceEnum.XAxis
    
    // Allow to interact with the annotation in run-time
    axisLabelAnnotation.setIsEditable(true)
    
    // In a multi-axis scenario, specify the XAxisId and YAxisId
    axisLabelAnnotation.xAxisId = "BottomAxisId"
    axisLabelAnnotation.yAxisId = "LeftAxisId"
    
    // Add the annotation to the Annotations collection of the surface
    surface.annotations.add(axisLabelAnnotation)
    
    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.

    Edit AxisLabelAnnotation in Run-Time

    Similarly to the TextAnnotation - AxisLabelAnnotation can be edited in run-time. To turn that on - just set setCanEditText(boolean canEditText) to true on your annotation.

    Note

    Be aware, if you use canEditText (allows edit text in run-time) in conjunction with isEditable (allows drag annotation over that chart), you will need to perform 2 taps - first one to select annotation, and only after that - tap to enter editing.

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