Search Results for

    Show / Hide Table of Contents

    Axis Labels - TextFormatting and CursorTextFormatting

    All the axis classes obey standard Cocoa formatting strings, calling methods of the Formatter APIs internally. Thus, standard Date Formatters and Number Formatters strings patterns can be applied to format axis labels. There are the setTextFormatting(String textFormatting) and setCursorTextFormatting(String cursorTextFormatting) properties for this purpose.

    Note

    DateFormat and NumberFormat relies on Unicode Technical Standard #35

    See possible string patterns provided by UTS#35

    • Number Format Patterns
    • Date Format Patterns

    Axis Labels Formatting

    Axis API allows to assign a formatting string for axis labels. There is the setTextFormatting(String textFormatting) property for this. Such formatting can be set in code as shown below:

    • Java
    • Java with Builders API
    • Kotlin
    final DateAxis xAxis = new DateAxis(getContext());
    xAxis.setTextFormatting("dd.MMM");
    
    final NumericAxis yAxis = new NumericAxis(getContext());
    yAxis.setTextFormatting("$0.0");
    
    final DateAxis xAxis = sciChartBuilder.newDateAxis()
            .withTextFormatting("dd.MMM")
            .build();
    
    final NumericAxis yAxis = sciChartBuilder.newNumericAxis()
            .withTextFormatting("$0.0")
            .build();
    
    val xAxis = DateAxis(context)
    xAxis.textFormatting = "dd.MMM"
    
    val yAxis = NumericAxis(context)
    yAxis.textFormatting = "$0.0"
    

    Axis Labels Formatting

    Note

    Axis labels formatting is also applied to AxisMarkerAnnotation labels.

    Axis Cursor Text Formatting

    Axis API allows to assign a formatting string for axis overlays, such as CursorModifier axis labels. Similarly to axis labels formatting, there is the setCursorTextFormatting(String cursorTextFormatting) property for this. Such formatting can be set in code as shown below:

    • Java
    • Java with Builders API
    • Kotlin
    final DateAxis xAxis = new DateAxis(getContext());
    xAxis.setCursorTextFormatting("'X Value:'dd.MM.yyyy");
    
    final NumericAxis yAxis = new NumericAxis(getContext());
    yAxis.setCursorTextFormatting("'Price:'###.##' $'");
    
    final DateAxis xAxis = sciChartBuilder.newDateAxis()
            .withCursorTextFormating("'X Value:'dd.MM.yyyy")
            .build();
    
    final NumericAxis yAxis = sciChartBuilder.newNumericAxis()
            .withCursorTextFormating("'Price:'###.##' $'")
            .build();
    
    val xAxis = DateAxis(context)
    xAxis.cursorTextFormatting = "'X Value:'dd.MM.yyyy"
    
    val yAxis = NumericAxis(context)
    yAxis.cursorTextFormatting = "'Price:'###.##' $'"
    

    Axis Cursor Text Formatting

    Numeric Axes and Scientific Notation

    It is possible to render axis labels and text in tooltips in a shortened form using scientific notation (standard form). This becomes an issue when working with large numbers. In this case axis size will grow to fit axis labels inside. This is a common issue when working with LogarithmicNumericAxis.

    To configure an axis to show numbers in this form, it is necessary that a proper format string is provided and ScientificNotation is set to the desired value. There is a scientificNotation property for this purpose. Possible options are listed below:

    • ScientificNotation.None - the default value.
    • ScientificNotation.Normalized - assumes 10 as base.
    • ScientificNotation.E - assumes the number E as base.
    • ScientificNotation.LogarithmicBase - used with LogarithmicNumericAxis. Assumes the logarithmic base of the LogarithmicNumericAxis as base.

    An axis can be configured to use ScientificNotation like follows:

    • Java
    • Java with Builders API
    • Kotlin
    LogarithmicNumericAxis xAxis = new LogarithmicNumericAxis(getContext());
    xAxis.setLogarithmicBase(10.0);
    xAxis.setScientificNotation(ScientificNotation.LogarithmicBase);
    xAxis.setTextFormatting("#.#E+0");
    xAxis.setCursorTextFormatting("#.#E+0");
    
    LogarithmicNumericAxis xAxis = sciChartBuilder.newLogarithmicNumericAxis()
            .withLogarithmicBase(10.0)
            .withScientificNotation(ScientificNotation.LogarithmicBase)
            .withTextFormatting("#.#E+0")
            .withCursorTextFormating("#.#E+0")
            .build();
    
    val xAxis = LogarithmicNumericAxis(context)
    xAxis.logarithmicBase = 10.0
    xAxis.scientificNotation = ScientificNotation.LogarithmicBase
    xAxis.textFormatting = "#.#E+0"
    xAxis.cursorTextFormatting = "#.#E+0"
    

    Axis Cursor Text Formatting

    Dynamically Changing TextFormatting

    For more advanced formatting scenarios, Axis API provides a feature called LabelProviders. It grants full control over text output of every axis label. This can be useful if required to customize textual representation of particular axis labels or replace all of them with other strings based on some logics. Please refer to the LabelProvider API article for further details.

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