NativeScript Core

Chart Negative Values

If you followed the getting started article, you now know how to create a chart and add it to a NativeScript page. In this article, you will see an example of using negative values and see how the chart will render them.

Getting Started

By default the LinearAxis supports the use of negative values. You can set the minimum minimum and/or the maximum to negative values.

Example 1: Using Negative Values

<navigation:ExamplePage xmlns:navigation="navigation/example-page" loaded="onPageLoaded" xmlns:chart="nativescript-ui-chart" xmlns="http://www.nativescript.org/tns.xsd">
    <chart:RadCartesianChart id="cartesianChart">
        <chart:RadCartesianChart.verticalAxis>
            <chart:LinearAxis allowZoom="true" minimum="-50" maximum="50"/>
        </chart:RadCartesianChart.verticalAxis>
        <chart:RadCartesianChart.horizontalAxis>
            <chart:CategoricalAxis allowZoom="true"/>
        </chart:RadCartesianChart.horizontalAxis>

        <chart:RadCartesianChart.series>
           <chart:SplineAreaSeries items="{{ negativeValues }}" categoryProperty="Period" valueProperty="Amount"></chart:SplineAreaSeries>
        </chart:RadCartesianChart.series>
    </chart:RadCartesianChart>
</navigation:ExamplePage>

This is how the chart will look like with negative values on the Y axis:

Figure 1: Chart with negative values on Android (left) and iOS (right)

Cartesian chart: Negative Values Cartesian chart: Negative Values

References

Want to see this scenario in action? Check our SDK Examples repository on GitHub. You will find this and many other practical examples with NativeScript UI.

Examples used in this article:

Related articles you might find useful: