Waterfall Chart in EJ2 TypeScript Charts
7 May 202524 minutes to read
Waterfall Chart
To render a waterfall series in your chart, you need to follow a few steps to configure it correctly. Here’s a concise guide on how to do this:
-
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. -
Inject the WaterfallSeries module: Use the
Chart.Inject(WaterfallSeries)method to inject theWaterfallSeriesmodule into your chart. This step is essential, as it ensures that the necessary functionalities for rendering waterfall series are available in your chart. -
Configure intermediate and cumulative sums: Use the
intermediateSumIndexesproperty property to represent intermediate sum values, and thesumIndexesproperty to represent cumulative sum values.
import { Chart, WaterfallSeries, Category } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(WaterfallSeries, Category);
let chart: Chart = new 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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ 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' }
];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.
import { Chart, WaterfallSeries, Category, DataLabel } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(WaterfallSeries, Category, DataLabel);
let chart: Chart = new 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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ 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' }
];Series customization
In waterfall charts, you can customize the appearance of different types of data changes using specific properties. The negativeFillColor property is used to specify the color for negative changes, which helps visually distinguish decreases in the data. Similarly, the summaryFillColor property is used to define the color for summary changes. By default, the negativeFillColor is set to green, indicating decreases, while the summaryFillColor is set to black, marking summary or total values.
import { Chart, WaterfallSeries, Category, DataLabel } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(WaterfallSeries, Category, DataLabel);
let chart: Chart = new 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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ 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' }
];Empty points
Data points with null or undefined values are considered empty. Empty data points are ignored and not plotted on the chart.
Mode
Use the mode property to define how empty or missing data points are handled in the series. The default mode for empty points is Gap.
import { Chart, WaterfallSeries, Category } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(WaterfallSeries, Category);
let chart: Chart = new 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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ 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' }
];Fill
Use the fill property to customize the fill color of empty points in the series.
import { Chart, WaterfallSeries, Category, DataLabel } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(WaterfallSeries, Category, DataLabel);
let chart: Chart = new 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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ 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' }
];Border
Use the border property to customize the width and color of the border for empty points.
import { Chart, WaterfallSeries, Category, DataLabel } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(WaterfallSeries, Category, DataLabel);
let chart: Chart = new 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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ 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' }
];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, giving your chart a more polished appearance. You can customize each corner of the bars using the topLeft, topRight, bottomLeft, and bottomRight properties.
import { Chart, WaterfallSeries, Category, IPointRenderEventArgs } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(WaterfallSeries, Category);
let chart: Chart = new 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: (args: IPointRenderEventArgs) => {
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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ 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' }
];Point corner radius
We 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.
import { Chart, WaterfallSeries, Category, IPointRenderEventArgs } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(WaterfallSeries, Category);
let chart: Chart = new Chart({
primaryXAxis: {
valueType: 'Category'
},
series: [
{
dataSource: chartData,
xName: 'x', yName: 'y',
intermediateSumIndexes: [4],
sumIndexes: [8],
//Series type as Waterfall
type: 'Waterfall'
}
],
pointRender: (args: IPointRenderEventArgs) => {
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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ 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' }
];Events
Series render
The seriesRender event allows you to customize series properties, such as data, fill, and name, before they are rendered on the chart.
import { Chart, WaterfallSeries, Category, ISeriesRenderEventArgs } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(WaterfallSeries, Category);
let chart: Chart = new Chart({
primaryXAxis: {
valueType: 'Category'
},
series: [
{
dataSource: chartData,
xName: 'x', yName: 'y',
intermediateSumIndexes: [4],
sumIndexes: [8],
//Series type as Waterfall
type: 'Waterfall'
}
],
seriesRender: (args: ISeriesRenderEventArgs) => {
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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ 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' }
];Point render
The pointRender event allows you to customize each data point before it is rendered on the chart.
import { Chart, WaterfallSeries, Category, IPointRenderEventArgs } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(WaterfallSeries, Category);
let chart: Chart = new Chart({
primaryXAxis: {
valueType: 'Category'
},
series: [
{
dataSource: chartData,
xName: 'x', yName: 'y',
intermediateSumIndexes: [4],
sumIndexes: [8],
//Series type as Waterfall
type: 'Waterfall'
}
],
pointRender: (args: IPointRenderEventArgs) => {
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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ 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' }
];