Description


This is an example of Javascript Chart with waterfall series. Waterfall series are used to display the cumulative effect of sequential data. You can see how to change the color via the colorFunction.

jQuery Chart: Waterfall Series

JavaScript Chart Waterfall Series Example.

A live JavaScript/jQuery example of jqxChart, the jQWidgets Chart component, with its complete source code below. It is one of 92 jqxChart demos for jQuery.

jqxChart API used in this demo

Source code

To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $. Getting started with jqxChart shows the setup step by step.

The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxdata.js, jqxdraw.js, jqxchart.core.js, jqxchart.waterfall.js.

It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers).

script.js

$(document).ready(function () {
    var data = [
        { year: 2006, population: 490815046 },
        { year: 2007, population: 492709300 },
        { year: 2008, population: 494774599 },
        { year: 2009, population: 496633373 },
        { year: 2010, population: 498408547 },
        { year: 2011, population: 500418320 },
        { year: 2012, population: 502186144 },
        { year: 2013, population: 503379305 },
        { year: 2014, population: 504961522 },
        { year: 2015, population: 504582506 },
        { year: 2016, population: 505674965 },
        { year: 2017, population: 507416607 },
        { year: 'Total', summary: true }
    ];

    // convert raw data to differences
    for (var i = data.length - 2; i > 0; i--)
        data[i].population -= data[i - 1].population;

    // prepare jqxChart settings
    var settings = {
        title: "EU Population between 2003 and 2018",
        description: "data source: Eurostat",
        enableAnimations: true,
        showLegend: false,
        padding: { left: 10, top: 5, right: 10, bottom: 5 },
        titlePadding: { left: 90, top: 0, right: 0, bottom: 10 },
        source: data,
        colorScheme: 'scheme06',
        xAxis:
        {
            type: 'basic',
            dataField: 'year',
            displayText: 'Year',
            labels: { angle: 0 }
        },
        valueAxis:
        {
            title: {text: 'Population<br>'},
            unitInterval: 1000000,
            labels:
            {
                formatFunction: function (value) {
                    return value / 1000000 + ' M';
                }
            }
        },
        seriesGroups:
            [
                {
                    type: 'waterfall',
                    series:
                    [
                        {
                            dataField: 'population',
                            summary: 'summary',
                            displayText: 'Population change',
                            colorFunction: function (value, itemIndex, serie, group) {
                                if (itemIndex == data.length - 1)
                                    return '#3F3A3B'; // total

                                return (value < 0) ? '#D30E2F' /* red */ : '#24A037' /*green*/;
                            }
                        }
                    ]
                }
            ]
    };

    // setup the chart
    $('#chartContainer').jqxChart(settings);

});

body.html

<div id="chartContainer" style="width:850px; height:500px">
</div>

Learn more

More jQuery Chart demos