Search Results for

    Show / Hide Table of Contents

    The AxisMarkerAnnotation

    The AxisMarkerAnnotation type allows to place markers with custom text onto X or Y axes. They show the axis value at their location by default:

    Axis Marker 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 AxisMarkerAnnotation can be configured using the properties listed in the table below:

    Feature Description
    setFormattedValue(CharSequence formattedValue) Allows to specify the text that will appear on the marker.
    setFormattedValueProvider(IFormattedValueProvider formattedValueProvider) Allows to override the default formatted value, which comes from an axis via an AxisInfo object. Please refer to the AxisMarkerAnnotation TextFormatting section to learn more.
    setFontStyle(FontStyle fontStyle) Determines the appearance of the text on the marker via the FontStyle object. Please refer to the Styling and Theming article to learn more.
    setMarkerPointWidth(int markerPointWidth) Allows to specify the length of the pointed end of the marker.
    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.

    The AxisMarkerAnnotation can be placed on the X-Axis or the Y-Axis which 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.

    Also, AxisMarkerAnnotation can be aligned relative to the X1 or Y1 coordinate by setting Anchor Points. For more information about the Anchor Points - refer to the corresponding section Annotations APIs article.

    Note

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

    Create an AxisMarkerAnnotation

    A simple AxisMarkerAnnotation 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 an AxisMarkerAnnotation
    final AxisMarkerAnnotation rightMarker = new AxisMarkerAnnotation(getContext());
    
    // Specify a desired position by setting the Y1 coordinate, since the marker is going to be located on an Y axis
    rightMarker.setY1(8);
    
    // Allow to interact with the annotation in run-time
    rightMarker.setIsEditable(true);
    
    // In a multi-axis scenario, specify the XAxisId and YAxisId
    rightMarker.setXAxisId("BottomAxisId");
    rightMarker.setYAxisId("RightAxisId");
    
    // Specify the background color for the marker
    rightMarker.setBackgroundColor(0xAA4083B7);
    
    // Add the annotation to the Annotations collection of the surface
    surface.getAnnotations().add(rightMarker);
    
    // Assume a surface has been created and configured somewhere
    // Create an AxisMarkerAnnotation
    final AxisMarkerAnnotation rightMarker = sciChartBuilder.newAxisMarkerAnnotation()
            // Specify a desired position by setting the Y1 coordinate, since the marker is going to be located on an Y axis
            .withY1(0)
            // Allow to interact with the annotation in run-time
            .withIsEditable(true)
            // In a multi-axis scenario, specify the XAxisId and YAxisId
            .withXAxisId("BottomAxisId")
            .withYAxisId("RightAxisId")
            // Specify the background color for the marker
            .withBackgroundColor(0xAA4083B7)
            .build();
    
    // Add the annotation to the Annotations collection of the surface
    surface.getAnnotations().add(rightMarker);
    
    // Assume a surface has been created and configured somewhere
    // Create an AxisMarkerAnnotation
    val rightMarker = AxisMarkerAnnotation(context)
    
    // Specify a desired position by setting the Y1 coordinate, since the marker is going to be located on an Y axis
    rightMarker.y1 = 8
    
    // Allow to interact with the annotation in run-time
    rightMarker.setIsEditable(true)
    
    // In a multi-axis scenario, specify the XAxisId and YAxisId
    rightMarker.xAxisId = "BottomAxisId"
    rightMarker.yAxisId = "RightAxisId"
    
    // Specify the background color for the marker
    rightMarker.setBackgroundColor(-0x55bf7c49)
    
    // Add the annotation to the Annotations collection of the surface
    surface.annotations.add(rightMarker)
    

    AxisMarkerAnnotation TextFormatting

    By default, the axis marker text is formatted by the textFormatting property. For more information, refer to the Axis Labels - TextFormatting and CursorTextFormatting article.

    But you can also override the default behaviour by using textformatting by providing custom the IFormattedValueProvider for your AxisMarkerAnnotation corresponding property.

    Let's see a short example which shows how to use the above:

    • Java
    • Java with Builders API
    • Kotlin
    // Declare custom IFormattedValueProvider
    class AnnotationValueProvider implements IFormattedValueProvider {
        @Override
        public CharSequence formatValue(AxisInfo axisInfo) {
            return axisInfo != null ? String.format("[ --- %s --- ]", axisInfo.axisFormattedDataValue) : null;
        }
    }
    
    // Provide custom IFormattedValueProvider for the annotation
    rightMarker.setFormattedValueProvider(new AnnotationValueProvider());
    
    // Declare custom IFormattedValueProvider
    class AnnotationValueProvider implements IFormattedValueProvider {
        @Override
        public CharSequence formatValue(AxisInfo axisInfo) {
            return axisInfo != null ? String.format("[ --- %s --- ]", axisInfo.axisFormattedDataValue) : null;
        }
    }
    
    // Provide custom IFormattedValueProvider for the annotation
    rightMarker.setFormattedValueProvider(new AnnotationValueProvider());
    
    // Declare custom IFormattedValueProvider
    internal class AnnotationValueProvider : IFormattedValueProvider {
        override fun formatValue(axisInfo: AxisInfo?): CharSequence? {
            return if (axisInfo != null) String.format(
                "[ --- %s --- ]",
                axisInfo.axisFormattedDataValue
            ) else null
        }
    }
    
    // Provide custom IFormattedValueProvider for the annotation
    rightMarker.formattedValueProvider = AnnotationValueProvider()
    

    which will result in the following:

    Axis Marker Annotation Formatting

    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