Waterfall Chart in JavaScript Charts
Waterfall Chart
To render a waterfall series in your chart, follow the steps below:
-
Set the series type: Define the series
typeasWaterfallin your chart configuration. This indicates that the data should be represented as a waterfall chart, which helps illustrate the cumulative effect of sequentially introduced positive and negative values.
The control is initialized with the remaining configuration in the next step. In JavaScript, the WaterfallSeries and Category modules are loaded through the script bundle; no explicit Chart.Inject(...) call is required.
-
Configure intermediate and cumulative sums: Use the
intermediateSumIndexesproperty to represent intermediate sum values, and thesumIndexesproperty to represent cumulative sum values.
var chartData = [
{ x: 'Income', y: 4711 }, { x: 'Sales', y: -1015 },
{ x: 'Development', y: -688 },
{ x: 'Revenue', y: 1030 }, { x: 'Balance' },
{ x: 'Administrative', y: -780 },
{ x: 'Expense', y: -361 }, { x: 'Tax', y: -695 },
{ x: 'Net Profit' }
];
var chart = new ej.charts.Chart({
primaryXAxis: {
valueType: 'Category'
},
series: [
{
dataSource: chartData,
xName: 'x', yName: 'y',
intermediateSumIndexes: [4],
sumIndexes: [8],
//Series type as Waterfall
type: 'Waterfall'
}
]
}, '#element');<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/35.2.12/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>Binding data with series
You can bind data to the chart using the dataSource property within the series configuration. This allows you to connect a JSON dataset or remote data to your chart. To display the data correctly, map the fields from the data to the chart series xName and yName properties.
var chartData = [
{ x: 'Income', y: 4711 }, { x: 'Sales', y: -1015 },
{ x: 'Development', y: -688 },
{ x: 'Revenue', y: 1030 }, { x: 'Balance' },
{ x: 'Administrative', y: -780 },
{ x: 'Expense', y: -361 }, { x: 'Tax', y: -695 },
{ x: 'Net Profit' }
];
var chart = new ej.charts.Chart({
primaryXAxis: {
valueType: 'Category'
},
series: [
{
dataSource: chartData,
xName: 'x', yName: 'y',
intermediateSumIndexes: [4],
sumIndexes: [8],
//Series type as Waterfall
type: 'Waterfall'
}
]
}, '#element');<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/35.2.12/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>Series customization
In waterfall charts, you can customize the appearance of different types of data changes using specific properties. The negativeFillColor property sets the color for negative (decrease) values, and the summaryFillColor property sets the color for summary (intermediate and total) values. The defaults are #C64E4A (red) for negative and #4E81BC (blue) for summary.
var chartData = [
{ x: 'Income', y: 4711 }, { x: 'Sales', y: -1015 },
{ x: 'Development', y: -688 },
{ x: 'Revenue', y: 1030 }, {x: 'Balance'},
{ x: 'Administrative', y: -780 },
{ x: 'Expense', y: -361 }, { x: 'Tax', y: -695 },
{ x: 'Net Profit'}
];
var chart = new ej.charts.Chart({
primaryXAxis: {
valueType: 'Category'
},
primaryYAxis:
{
labelFormat: '${value}M'
},
series: [
{
dataSource: chartData,
xName: 'x', yName: 'y',
intermediateSumIndexes: [4],
sumIndexes: [8],
//Series type as Waterfall
type: 'Waterfall',
summaryFillColor: "black",
negativeFillColor:'green',
connector: { color: 'blue', width: 1.5 },
marker: {
dataLabel: {
visible: true,
position: 'Outer',
font: { size: '11px' }
}
}
}
],
title: 'Company Revenue and Profit'
}, '#element');<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/35.2.12/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>Empty points
Data points with null or undefined values are considered empty. Configure the emptyPointSettings on the series to control how empty data points are rendered.
Mode
Use the mode property to control handling of empty points. Available modes are Gap, Drop, Zero, and Average. The default mode is Gap.
var chartData = [
{ x: 'Income', y: 4711 }, { x: 'Sales', y: -1015 },
{ x: 'Development', y: -688 },
{ x: 'Revenue', y: null }, { x: 'Balance' },
{ x: 'Administrative', y: -780 },
{ x: 'Expense', y: -361 }, { x: 'Tax', y: -695 },
{ x: 'Net Profit' }
];
var chart = new ej.charts.Chart({
primaryXAxis: {
valueType: 'Category'
},
series: [
{
dataSource: chartData,
xName: 'x', yName: 'y',
intermediateSumIndexes: [4],
sumIndexes: [8],
type: 'Waterfall',
emptyPointSettings: {
mode: 'Average'
}
}
]
}, '#element');<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/35.2.12/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>Fill
Use the fill property to set the fill color for empty points.
var chartData = [
{ x: 'Income', y: 4711 }, { x: 'Sales', y: -1015 },
{ x: 'Development', y: -688 },
{ x: 'Revenue', y: null }, { x: 'Balance' },
{ x: 'Administrative', y: -780 },
{ x: 'Expense', y: -361 }, { x: 'Tax', y: -695 },
{ x: 'Net Profit' }
];
var chart = new ej.charts.Chart({
primaryXAxis: {
valueType: 'Category'
},
series: [
{
dataSource: chartData,
xName: 'x', yName: 'y',
intermediateSumIndexes: [4],
sumIndexes: [8],
type: 'Waterfall',
emptyPointSettings: {
mode: 'Average',
fill: 'red'
}
}
]
}, '#element');<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/35.2.12/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>Border
Use the border property to customize the border width and color for empty points.
var chartData = [
{ x: 'Income', y: 4711 }, { x: 'Sales', y: -1015 },
{ x: 'Development', y: -688 },
{ x: 'Revenue', y: null }, { x: 'Balance' },
{ x: 'Administrative', y: -780 },
{ x: 'Expense', y: -361 }, { x: 'Tax', y: -695 },
{ x: 'Net Profit' }
];
var chart = new ej.charts.Chart({
primaryXAxis: {
valueType: 'Category'
},
series: [
{
dataSource: chartData,
xName: 'x', yName: 'y',
intermediateSumIndexes: [4],
sumIndexes: [8],
type: 'Waterfall',
emptyPointSettings: {
mode: 'Average',
fill: 'red',
border: { width: 2, color: 'green' }
}
}
]
}, '#element');<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/35.2.12/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>Corner radius
The cornerRadius property in the chart series is used to customize the corner radius for bar series. This allows you to create bars with rounded corners. You can customize each corner of the bars using the topLeft, topRight, bottomLeft, and bottomRight properties.
var chartData = [
{ x: 'Income', y: 4711 }, { x: 'Sales', y: -1015 },
{ x: 'Development', y: -688 },
{ x: 'Revenue', y: 1030 }, { x: 'Balance' },
{ x: 'Administrative', y: -780 },
{ x: 'Expense', y: -361 }, { x: 'Tax', y: -695 },
{ x: 'Net Profit' }
];
var chart = new ej.charts.Chart({
primaryXAxis: {
valueType: 'Category'
},
series: [
{ cornerRadius: { topRight: 10, topLeft: 10 },
dataSource: chartData,
xName: 'x', yName: 'y',
intermediateSumIndexes: [4],
sumIndexes: [8],
//Series type as Waterfall
type: 'Waterfall'
}
],
pointRender: function (args) {
if (args.point.index % 2 !== 0) {
args.fill = '#ff6347';
}
else {
args.fill = '#009cb8';
}
}
}, '#element');<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/35.2.12/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>Point corner radius
You can customize the corner radius for individual points in the chart series using the pointRender event by setting the cornerRadius property in its event argument.
var chartData = [
{ x: 'Income', y: 4711 }, { x: 'Sales', y: -1015 },
{ x: 'Development', y: -688 },
{ x: 'Revenue', y: 1030 }, { x: 'Balance' },
{ x: 'Administrative', y: -780 },
{ x: 'Expense', y: -361 }, { x: 'Tax', y: -695 },
{ x: 'Net Profit' }
];
var chart = new ej.charts.Chart({
primaryXAxis: {
valueType: 'Category'
},
series: [
{
dataSource: chartData,
xName: 'x', yName: 'y',
intermediateSumIndexes: [4],
sumIndexes: [8],
//Series type as Waterfall
type: 'Waterfall'
}
],
pointRender: function (args) {
if (args.point.index === 0) {
args.cornerRadius = { topLeft: 10, bottomLeft: 0, topRight: 10, bottomRight: 0 };
}
if (args.point.index === 3 ) {
args.cornerRadius = { topLeft: 10, bottomLeft: 0, topRight: 10, bottomRight: 0 };
}
if (args.point.index === 4 ) {
args.cornerRadius = { topLeft: 10, bottomLeft: 0, topRight: 10, bottomRight: 0 };
}
if (args.point.index === 6 ) {
args.cornerRadius = { topLeft: 10, bottomLeft: 0, topRight: 10, bottomRight: 0 };
}
}
}, '#element');<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/35.2.12/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>Events
Series render
The seriesRender event enables modification of series properties (for example, data, fill, or name) immediately before rendering. Use this event to adjust series appearance or to dynamically swap data sources.
var chartData = [
{ x: 'Income', y: 4711 }, { x: 'Sales', y: -1015 },
{ x: 'Development', y: -688 },
{ x: 'Revenue', y: 1030 }, { x: 'Balance' },
{ x: 'Administrative', y: -780 },
{ x: 'Expense', y: -361 }, { x: 'Tax', y: -695 },
{ x: 'Net Profit' }
];
var chart = new ej.charts.Chart({
primaryXAxis: {
valueType: 'Category'
},
series: [
{
dataSource: chartData,
xName: 'x', yName: 'y',
intermediateSumIndexes: [4],
sumIndexes: [8],
//Series type as Waterfall
type: 'Waterfall'
}
],
seriesRender: function (args) {
args.fill = '#ff6347';
args.series.negativeFillColor = '#ff6347';
args.series.summaryFillColor = '#ff6347';
}
}, '#element');<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/35.2.12/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>Point render
The pointRender event provides a hook to customize each data point (for example, marker shape, border, or fill) before it is drawn. Use this to apply per-point styling rules or conditional formatting.
var chartData = [
{ x: 'Income', y: 4711 }, { x: 'Sales', y: -1015 },
{ x: 'Development', y: -688 },
{ x: 'Revenue', y: 1030 }, { x: 'Balance' },
{ x: 'Administrative', y: -780 },
{ x: 'Expense', y: -361 }, { x: 'Tax', y: -695 },
{ x: 'Net Profit' }
];
var chart = new ej.charts.Chart({
primaryXAxis: {
valueType: 'Category'
},
series: [
{
dataSource: chartData,
xName: 'x', yName: 'y',
intermediateSumIndexes: [4],
sumIndexes: [8],
//Series type as Waterfall
type: 'Waterfall'
}
],
pointRender: function (args) {
if (args.point.index % 2 !== 0) {
args.fill = '#ff6347';
}
else {
args.fill = '#009cb8';
}
}
}, '#element');<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Animation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Typescript UI Controls">
<meta name="author" content="Syncfusion">
<link href="index.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/35.2.12/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>Troubleshooting
The following list describes common issues you may encounter when working with the Waterfall series and how to resolve them.
Chart does not render as a waterfall: Confirm the type property of each series is set to Waterfall. In JavaScript, the WaterfallSeries and Category modules are loaded through the script bundle; no explicit Chart.Inject(...) call is required.
Intermediate or cumulative sums do not appear: intermediateSumIndexes and sumIndexes accept arrays of point indexes. Verify that each index references a valid point in the data source; indexes that are out of range or that point to summary points already declared by the other property are ignored.
Negative or summary colors look wrong: The default negativeFillColor is #C64E4A (red) and summaryFillColor is #4E81BC (blue). Set them explicitly to override the defaults.