Waterfall Chart
A demo of amCharts 4, the previous version. For a new project, start from the amCharts 5 demos.
Waterfall Chart (also known as Flying bricks chart, Mario chart, Cascade chart) is most frequently used to display the effect of the series of consecutive positive or negative events on the initial value.
Mixed series types
amCharts 4 allows mixing a number of different series on the same chart. This particular Waterfall chart is enabled by combining a floating Column series and a no-riser Step series.
Flexible line start and end location setting enables fine-tuning connector line position for perfect fit.
More about making a waterfall chart
Open in:
Code
JavaScript
// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end
var chart = am4core.create("chartdiv", am4charts.XYChart);
chart.hiddenState.properties.opacity = 0; // this makes initial fade in effect
// using math in the data instead of final values just to illustrate the idea of Waterfall chart
// a separate data field for step series is added because we don't need last step (notice, the last data item doesn't have stepValue)
chart.data = [ {
category: "Net revenue",
value: 8786,
open: 0,
stepValue: 8786,
color: chart.colors.getIndex( 13 ),
displayValue: 8786
}, {
category: "Cost of sales",
value: 8786 - 2786,
open: 8786,
stepValue: 8786 - 2786,
color: chart.colors.getIndex( 8 ),
displayValue: 2786
}, {
category: "Operating expenses",
value: 8786 - 2786 - 1786,
open: 8786 - 2786,
stepValue: 8786 - 2786 - 1786,
color: chart.colors.getIndex( 9 ),
displayValue: 1786
}, {
category: "Amortisation",
value: 8786 - 2786 - 1786 - 453,
open: 8786 - 2786 - 1786,
stepValue: 8786 - 2786 - 1786 - 453,
color: chart.colors.getIndex( 10 ),
displayValue: 453
}, {
category: "Income from equity",
value: 8786 - 2786 - 1786 - 453 + 1465,
open: 8786 - 2786 - 1786 - 453,
stepValue: 8786 - 2786 - 1786 - 453 + 1465,
color: chart.colors.getIndex( 16 ),
displayValue: 1465
}, {
category: "Operating income",
value: 8786 - 2786 - 1786 - 453 + 1465,
open: 0,
color: chart.colors.getIndex( 17 ),
displayValue: 8786 - 2786 - 1786 - 453 + 1465
} ];
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "category";
categoryAxis.renderer.minGridDistance = 40;
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
var columnSeries = chart.series.push(new am4charts.ColumnSeries());
columnSeries.dataFields.categoryX = "category";
columnSeries.dataFields.valueY = "value";
columnSeries.dataFields.openValueY = "open";
columnSeries.fillOpacity = 0.8;
columnSeries.sequencedInterpolation = true;
columnSeries.interpolationDuration = 1500;
var columnTemplate = columnSeries.columns.template;
columnTemplate.strokeOpacity = 0;
columnTemplate.propertyFields.fill = "color";
var label = columnTemplate.createChild(am4core.Label);
label.text = "{displayValue.formatNumber('$#,## a')}";
label.align = "center";
label.valign = "middle";
var stepSeries = chart.series.push(new am4charts.StepLineSeries());
stepSeries.dataFields.categoryX = "category";
stepSeries.dataFields.valueY = "stepValue";
stepSeries.noRisers = true;
stepSeries.stroke = new am4core.InterfaceColorSet().getFor("alternativeBackground");
stepSeries.strokeDasharray = "3,3";
stepSeries.interpolationDuration = 2000;
stepSeries.sequencedInterpolation = true;
// because column width is 80%, we modify start/end locations so that step would start with column and end with next column
stepSeries.startLocation = 0.1;
stepSeries.endLocation = 1.1;
chart.cursor = new am4charts.XYCursor();
chart.cursor.behavior = "none";
HTML
<div id="chartdiv"></div>
CSS
#chartdiv {
width: 100%;
height: 500px
}
Resources
https://cdn.amcharts.com/lib/4/core.js
https://cdn.amcharts.com/lib/4/charts.js
https://cdn.amcharts.com/lib/4/themes/animated.js
All in one page
<!-- Resources -->
<script src="https://cdn.amcharts.com/lib/4/core.js"></script>
<script src="https://cdn.amcharts.com/lib/4/charts.js"></script>
<script src="https://cdn.amcharts.com/lib/4/themes/animated.js"></script>
<!-- Chart code -->
<script>
// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end
var chart = am4core.create("chartdiv", am4charts.XYChart);
chart.hiddenState.properties.opacity = 0; // this makes initial fade in effect
// using math in the data instead of final values just to illustrate the idea of Waterfall chart
// a separate data field for step series is added because we don't need last step (notice, the last data item doesn't have stepValue)
chart.data = [ {
category: "Net revenue",
value: 8786,
open: 0,
stepValue: 8786,
color: chart.colors.getIndex( 13 ),
displayValue: 8786
}, {
category: "Cost of sales",
value: 8786 - 2786,
open: 8786,
stepValue: 8786 - 2786,
color: chart.colors.getIndex( 8 ),
displayValue: 2786
}, {
category: "Operating expenses",
value: 8786 - 2786 - 1786,
open: 8786 - 2786,
stepValue: 8786 - 2786 - 1786,
color: chart.colors.getIndex( 9 ),
displayValue: 1786
}, {
category: "Amortisation",
value: 8786 - 2786 - 1786 - 453,
open: 8786 - 2786 - 1786,
stepValue: 8786 - 2786 - 1786 - 453,
color: chart.colors.getIndex( 10 ),
displayValue: 453
}, {
category: "Income from equity",
value: 8786 - 2786 - 1786 - 453 + 1465,
open: 8786 - 2786 - 1786 - 453,
stepValue: 8786 - 2786 - 1786 - 453 + 1465,
color: chart.colors.getIndex( 16 ),
displayValue: 1465
}, {
category: "Operating income",
value: 8786 - 2786 - 1786 - 453 + 1465,
open: 0,
color: chart.colors.getIndex( 17 ),
displayValue: 8786 - 2786 - 1786 - 453 + 1465
} ];
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "category";
categoryAxis.renderer.minGridDistance = 40;
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
var columnSeries = chart.series.push(new am4charts.ColumnSeries());
columnSeries.dataFields.categoryX = "category";
columnSeries.dataFields.valueY = "value";
columnSeries.dataFields.openValueY = "open";
columnSeries.fillOpacity = 0.8;
columnSeries.sequencedInterpolation = true;
columnSeries.interpolationDuration = 1500;
var columnTemplate = columnSeries.columns.template;
columnTemplate.strokeOpacity = 0;
columnTemplate.propertyFields.fill = "color";
var label = columnTemplate.createChild(am4core.Label);
label.text = "{displayValue.formatNumber('$#,## a')}";
label.align = "center";
label.valign = "middle";
var stepSeries = chart.series.push(new am4charts.StepLineSeries());
stepSeries.dataFields.categoryX = "category";
stepSeries.dataFields.valueY = "stepValue";
stepSeries.noRisers = true;
stepSeries.stroke = new am4core.InterfaceColorSet().getFor("alternativeBackground");
stepSeries.strokeDasharray = "3,3";
stepSeries.interpolationDuration = 2000;
stepSeries.sequencedInterpolation = true;
// because column width is 80%, we modify start/end locations so that step would start with column and end with next column
stepSeries.startLocation = 0.1;
stepSeries.endLocation = 1.1;
chart.cursor = new am4charts.XYCursor();
chart.cursor.behavior = "none";
</script>
<!-- HTML -->
<div id="chartdiv"></div>