Events in TypeScript Sankey Chart component
18 Nov 201824 minutes to read
The Sankey Chart provides comprehensive events that allow you to customize behavior, respond to user interactions, and hook into the chart lifecycle. These events enable advanced customization scenarios including data transformation, analytics tracking, and dynamic UI updates.
This guide covers lifecycle events, rendering events, interaction events, and export/print events.
Event List
| Event | Description |
|---|---|
| load | Triggers before the Sankey loads. Allows customization before rendering. |
| loaded | Triggers after the Sankey is fully loaded and rendered. |
| legendItemRendering | Triggers before a legend item is rendered. Allows customization of legend items. |
| labelRendering | Triggers before a label is rendered. Allows customization of label text and style. |
| nodeRendering | Triggers before a node is rendered. Allows customization of node appearance. |
| linkRendering | Triggers before a link is rendered. Allows customization of link appearance. |
| tooltipRendering | Triggers before a tooltip is rendered. Allows customization of tooltip content. |
| nodeClick | Triggers when a node is clicked. |
| nodeEnter | Triggers when the mouse enters a node area. |
| nodeLeave | Triggers when the mouse leaves a node area. |
| linkClick | Triggers when a link is clicked. |
| linkEnter | Triggers when the mouse enters a link area. |
| linkLeave | Triggers when the mouse leaves a link area. |
| sizeChanged | Triggers when the chart size changes. |
| beforeExport | Triggers before the export process starts. |
| afterExport | Triggers after the export process completes. |
| exportCompleted | Triggers when export is completed. |
| beforePrint | Triggers before the print process starts. |
Lifecycle Events
Load Event
The load event triggers before the Sankey Chart begins rendering. Use this event to customize configuration, apply themes, or prepare data before the chart loads:
import { Sankey, SankeyNodeModel, SankeyLinkModel, SankeyTooltip, SankeyLegend, SankeyExport, ILoadedEventArgs } from '@syncfusion/ej2-charts';
Sankey.Inject(SankeyTooltip, SankeyLegend, SankeyExport);
const onLoad = (args: ILoadedEventArgs) => {
console.log('Sankey chart is loading...', args);
};
const nodes: SankeyNodeModel[] = [
{ id: 'Agricultural Waste' },
{ id: 'Bio-conversion' },
{ id: 'Liquid Biofuel' },
{ id: 'Electricity' },
{ id: 'Heat' }
];
const links: SankeyLinkModel[] = [
{ sourceId: 'Agricultural Waste', targetId: 'Bio-conversion', value: 124.729 },
{ sourceId: 'Bio-conversion', targetId: 'Liquid Biofuel', value: 0.597 },
{ sourceId: 'Bio-conversion', targetId: 'Electricity', value: 26.862 },
{ sourceId: 'Bio-conversion', targetId: 'Heat', value: 280.845 }
];
const sankey: Sankey = new Sankey(
{
width: '90%',
height: '450px',
load: onLoad,
nodes: nodes,
links: links,
tooltip: { enable: true },
legendSettings: { visible: true }
},
'#sankey-container'
);<!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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='sankey-container'></div>
</div>
</body>
</html>Loaded Event
The loaded event triggers after the Sankey Chart is completely rendered and ready for interaction. Use this event to initialize calculations, perform analytics, or trigger dependent components:
import { Sankey, SankeyNodeModel, SankeyLinkModel, SankeyTooltip, SankeyLegend, SankeyExport, ILoadedEventArgs } from '@syncfusion/ej2-charts';
Sankey.Inject(SankeyTooltip, SankeyLegend, SankeyExport);
const nodes: SankeyNodeModel[] = [
{ id: 'Agricultural Waste' },
{ id: 'Biomass Residues' },
{ id: 'Bio-conversion' },
{ id: 'Liquid Biofuel' },
{ id: 'Electricity' },
{ id: 'Heat' }
];
const links: SankeyLinkModel[] = [
{ sourceId: 'Agricultural Waste', targetId: 'Bio-conversion', value: 84.152 },
{ sourceId: 'Biomass Residues', targetId: 'Bio-conversion', value: 24.152 },
{ sourceId: 'Bio-conversion', targetId: 'Liquid Biofuel', value: 10.597 },
{ sourceId: 'Bio-conversion', targetId: 'Electricity', value: 36.862 },
{ sourceId: 'Bio-conversion', targetId: 'Heat', value: 60.845 }
];
const onLoaded = (args: ILoadedEventArgs) => {
console.log('Sankey chart has loaded successfully', args);
};
const sankey: Sankey = new Sankey(
{
width: '90%',
height: '450px',
loaded: onLoaded,
nodes: nodes,
links: links,
tooltip: { enable: true },
legendSettings: { visible: true }
},
'#sankey-container'
);<!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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='sankey-container'></div>
</div>
</body>
</html>Interaction Events
Node Interaction Events
Handle node click and hover events to respond to user actions and provide interactive feedback:
import { Sankey, SankeyNodeModel, SankeyLinkModel, SankeyTooltip, SankeyLegend, SankeyExport, SankeyNodeEventArgs } from '@syncfusion/ej2-charts';
Sankey.Inject(SankeyTooltip, SankeyLegend, SankeyExport);
const nodes: SankeyNodeModel[] = [
{ id: 'Agricultural Waste' },
{ id: 'Biomass Residues' },
{ id: 'Bio-conversion' },
{ id: 'Liquid Biofuel' },
{ id: 'Electricity' },
{ id: 'Heat' }
];
const links: SankeyLinkModel[] = [
{ sourceId: 'Agricultural Waste', targetId: 'Bio-conversion', value: 84.152 },
{ sourceId: 'Biomass Residues', targetId: 'Bio-conversion', value: 24.152 },
{ sourceId: 'Bio-conversion', targetId: 'Liquid Biofuel', value: 10.597 },
{ sourceId: 'Bio-conversion', targetId: 'Electricity', value: 36.862 },
{ sourceId: 'Bio-conversion', targetId: 'Heat', value: 60.845 }
];
const onNodeMouseClick = (args: SankeyNodeEventArgs) => {
console.log('Node clicked:', args.node);
};
const onNodeMouseEnter = (args: SankeyNodeEventArgs) => {
console.log('Node hovered:', args.node);
};
const sankey: Sankey = new Sankey(
{
width: '90%',
height: '450px',
nodeClick: onNodeMouseClick,
nodeEnter: onNodeMouseEnter,
nodes: nodes,
links: links,
tooltip: { enable: true },
legendSettings: { visible: true }
},
'#sankey-container'
);<!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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='sankey-container'></div>
</div>
</body>
</html>Link Interaction Events
Handle link click and hover events:
import { Sankey, SankeyNodeModel, SankeyLinkModel, SankeyTooltip, SankeyLegend, SankeyExport, SankeyLinkEventArgs } from '@syncfusion/ej2-charts';
Sankey.Inject(SankeyTooltip, SankeyLegend, SankeyExport);
const nodes: SankeyNodeModel[] = [
{ id: 'Agricultural Waste' },
{ id: 'Biomass Residues' },
{ id: 'Bio-conversion' },
{ id: 'Liquid Biofuel' },
{ id: 'Electricity' },
{ id: 'Heat' }
];
const links: SankeyLinkModel[] = [
{ sourceId: 'Agricultural Waste', targetId: 'Bio-conversion', value: 84.152 },
{ sourceId: 'Biomass Residues', targetId: 'Bio-conversion', value: 24.152 },
{ sourceId: 'Bio-conversion', targetId: 'Liquid Biofuel', value: 10.597 },
{ sourceId: 'Bio-conversion', targetId: 'Electricity', value: 36.862 },
{ sourceId: 'Bio-conversion', targetId: 'Heat', value: 60.845 }
];
const onLinkMouseClick = (args: SankeyLinkEventArgs) => {
console.log('Link clicked:', args.link);
};
const onLinkMouseEnter = (args: SankeyLinkEventArgs) => {
console.log('Link hovered:', args.link);
};
const sankey: Sankey = new Sankey(
{
width: '90%',
height: '450px',
linkClick: onLinkMouseClick,
linkEnter: onLinkMouseEnter,
nodes: nodes,
links: links,
tooltip: { enable: true },
legendSettings: { visible: true }
},
'#sankey-container'
);<!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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='sankey-container'></div>
</div>
</body>
</html>Rendering Events
Use rendering events to customize elements dynamically based on data values, conditions, or business logic. This is the most powerful approach for data-driven styling.
Node Rendering Event
The nodeRendering event triggers before each node is rendered, allowing dynamic node customization:
import { Sankey, SankeyNodeModel, SankeyLinkModel, SankeyTooltip, SankeyLegend, SankeyExport, SankeyNodeEventArgs } from '@syncfusion/ej2-charts';
Sankey.Inject(SankeyTooltip, SankeyLegend, SankeyExport);
const nodes: SankeyNodeModel[] = [
{ id: 'Agricultural Waste' },
{ id: 'Biomass Residues' },
{ id: 'Bio-conversion' },
{ id: 'Liquid Biofuel' },
{ id: 'Electricity' },
{ id: 'Heat' }
];
const links: SankeyLinkModel[] = [
{ sourceId: 'Agricultural Waste', targetId: 'Bio-conversion', value: 84.152 },
{ sourceId: 'Biomass Residues', targetId: 'Bio-conversion', value: 24.152 },
{ sourceId: 'Bio-conversion', targetId: 'Liquid Biofuel', value: 10.597 },
{ sourceId: 'Bio-conversion', targetId: 'Electricity', value: 36.862 },
{ sourceId: 'Bio-conversion', targetId: 'Heat', value: 60.845 }
];
const onNodeMouseClick = (args: SankeyNodeEventArgs) => {
console.log('Node clicked:', args.node);
};
const onNodeMouseEnter = (args: SankeyNodeEventArgs) => {
console.log('Node hovered:', args.node);
};
const sankey: Sankey = new Sankey(
{
width: '90%',
height: '450px',
nodeClick: onNodeMouseClick,
nodeEnter: onNodeMouseEnter,
nodes: nodes,
links: links,
tooltip: { enable: true },
legendSettings: { visible: true }
},
'#sankey-container'
);<!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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='sankey-container'></div>
</div>
</body>
</html>Link Rendering Event
The linkRendering event triggers before each link is rendered, allowing dynamic link customization:
import { Sankey, SankeyNodeModel, SankeyLinkModel, SankeyTooltip, SankeyLegend, SankeyExport, SankeyLinkEventArgs } from '@syncfusion/ej2-charts';
Sankey.Inject(SankeyTooltip, SankeyLegend, SankeyExport);
const nodes: SankeyNodeModel[] = [
{ id: 'Agricultural Waste' },
{ id: 'Biomass Residues' },
{ id: 'Bio-conversion' },
{ id: 'Liquid Biofuel' },
{ id: 'Electricity' },
{ id: 'Heat' }
];
const links: SankeyLinkModel[] = [
{ sourceId: 'Agricultural Waste', targetId: 'Bio-conversion', value: 84.152 },
{ sourceId: 'Biomass Residues', targetId: 'Bio-conversion', value: 24.152 },
{ sourceId: 'Bio-conversion', targetId: 'Liquid Biofuel', value: 10.597 },
{ sourceId: 'Bio-conversion', targetId: 'Electricity', value: 36.862 },
{ sourceId: 'Bio-conversion', targetId: 'Heat', value: 60.845 }
];
const onLinkMouseClick = (args: SankeyLinkEventArgs) => {
console.log('Link clicked:', args.link);
};
const onLinkMouseEnter = (args: SankeyLinkEventArgs) => {
console.log('Link hovered:', args.link);
};
const sankey: Sankey = new Sankey(
{
width: '90%',
height: '450px',
linkClick: onLinkMouseClick,
linkEnter: onLinkMouseEnter,
nodes: nodes,
links: links,
tooltip: { enable: true },
legendSettings: { visible: true }
},
'#sankey-container'
);<!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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='sankey-container'></div>
</div>
</body>
</html>Label Rendering Event
The labelRendering event triggers before each label is rendered, allowing dynamic label customization:
import { Sankey, SankeyNodeModel, SankeyLinkModel, SankeyTooltip, SankeyLegend, SankeyExport, ILoadedEventArgs } from '@syncfusion/ej2-charts';
Sankey.Inject(SankeyTooltip, SankeyLegend, SankeyExport);
const nodes: SankeyNodeModel[] = [
{ id: 'Agricultural Waste' },
{ id: 'Biomass Residues' },
{ id: 'Bio-conversion' },
{ id: 'Liquid Biofuel' },
{ id: 'Electricity' },
{ id: 'Heat' }
];
const links: SankeyLinkModel[] = [
{ sourceId: 'Agricultural Waste', targetId: 'Bio-conversion', value: 84.152 },
{ sourceId: 'Biomass Residues', targetId: 'Bio-conversion', value: 24.152 },
{ sourceId: 'Bio-conversion', targetId: 'Liquid Biofuel', value: 10.597 },
{ sourceId: 'Bio-conversion', targetId: 'Electricity', value: 36.862 },
{ sourceId: 'Bio-conversion', targetId: 'Heat', value: 60.845 }
];
const onLoadComplete = (args: ILoadedEventArgs) => {
const element = document.getElementById('sankey-container');
if (element) element.setAttribute('title', 'Sankey Chart Ready');
};
const sankey: Sankey = new Sankey(
{
width: '90%',
height: '450px',
loaded: onLoadComplete,
nodes: nodes,
links: links,
tooltip: { enable: true },
legendSettings: { visible: true }
},
'#sankey-container'
);<!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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='sankey-container'></div>
</div>
</body>
</html>Legend Item Rendering Event
The legendItemRendering event triggers before a legend item is rendered, allowing custom legend item styling:
import { Sankey, SankeyNodeModel, SankeyLinkModel, SankeyTooltip, SankeyLegend, SankeyExport, ILoadedEventArgs } from '@syncfusion/ej2-charts';
Sankey.Inject(SankeyTooltip, SankeyLegend, SankeyExport);
const nodes: SankeyNodeModel[] = [
{ id: 'Agricultural Waste' },
{ id: 'Biomass Residues' },
{ id: 'Bio-conversion' },
{ id: 'Liquid Biofuel' },
{ id: 'Electricity' },
{ id: 'Heat' }
];
const links: SankeyLinkModel[] = [
{ sourceId: 'Agricultural Waste', targetId: 'Bio-conversion', value: 84.152 },
{ sourceId: 'Biomass Residues', targetId: 'Bio-conversion', value: 24.152 },
{ sourceId: 'Bio-conversion', targetId: 'Liquid Biofuel', value: 10.597 },
{ sourceId: 'Bio-conversion', targetId: 'Electricity', value: 36.862 },
{ sourceId: 'Bio-conversion', targetId: 'Heat', value: 60.845 }
];
const onLoadComplete = (args: ILoadedEventArgs) => {
const element = document.getElementById('sankey-container');
if (element) element.setAttribute('title', 'Sankey Chart Ready');
};
const sankey: Sankey = new Sankey(
{
width: '90%',
height: '450px',
loaded: onLoadComplete,
nodes: nodes,
links: links,
tooltip: { enable: true },
legendSettings: { visible: true }
},
'#sankey-container'
);<!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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='sankey-container'></div>
</div>
</body>
</html>Size Changed Event
Respond when the chart size changes (e.g., window resize):
import { Sankey, SankeyNodeModel, SankeyLinkModel, SankeyTooltip, SankeyLegend, SankeyExport, SankeySizeChangedEventArgs } from '@syncfusion/ej2-charts';
Sankey.Inject(SankeyTooltip, SankeyLegend, SankeyExport);
const nodes: SankeyNodeModel[] = [
{ id: 'Agricultural Waste' },
{ id: 'Biomass Residues' },
{ id: 'Bio-conversion' },
{ id: 'Liquid Biofuel' },
{ id: 'Electricity' },
{ id: 'Heat' }
];
const links: SankeyLinkModel[] = [
{ sourceId: 'Agricultural Waste', targetId: 'Bio-conversion', value: 84.152 },
{ sourceId: 'Biomass Residues', targetId: 'Bio-conversion', value: 24.152 },
{ sourceId: 'Bio-conversion', targetId: 'Liquid Biofuel', value: 10.597 },
{ sourceId: 'Bio-conversion', targetId: 'Electricity', value: 36.862 },
{ sourceId: 'Bio-conversion', targetId: 'Heat', value: 60.845 }
];
const onSizeChanged = (args: SankeySizeChangedEventArgs) => {
console.log('Chart size changed:', { width: args.currentSize.width, height: args.currentSize.height });
};
const sankey: Sankey = new Sankey(
{
width: '90%',
height: '450px',
sizeChanged: onSizeChanged,
nodes: nodes,
links: links,
tooltip: { enable: true },
legendSettings: { visible: true }
},
'#sankey-container'
);<!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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='sankey-container'></div>
</div>
</body>
</html>Complete Event Handler Example
Combine multiple events for comprehensive handling:
import { Sankey, SankeyNodeModel, SankeyLinkModel, SankeyTooltip, SankeyLegend, SankeyExport, ILoadedEventArgs } from '@syncfusion/ej2-charts';
Sankey.Inject(SankeyTooltip, SankeyLegend, SankeyExport);
const nodes: SankeyNodeModel[] = [
{ id: 'Agricultural Waste' },
{ id: 'Biomass Residues' },
{ id: 'Bio-conversion' },
{ id: 'Liquid Biofuel' },
{ id: 'Electricity' },
{ id: 'Heat' }
];
const links: SankeyLinkModel[] = [
{ sourceId: 'Agricultural Waste', targetId: 'Bio-conversion', value: 84.152 },
{ sourceId: 'Biomass Residues', targetId: 'Bio-conversion', value: 24.152 },
{ sourceId: 'Bio-conversion', targetId: 'Liquid Biofuel', value: 10.597 },
{ sourceId: 'Bio-conversion', targetId: 'Electricity', value: 36.862 },
{ sourceId: 'Bio-conversion', targetId: 'Heat', value: 60.845 }
];
const onLoadComplete = (args: ILoadedEventArgs) => {
const element = document.getElementById('sankey-container');
if (element) element.setAttribute('title', 'Sankey Chart Ready');
};
const sankey: Sankey = new Sankey(
{
width: '90%',
height: '450px',
loaded: onLoadComplete,
nodes: nodes,
links: links,
tooltip: { enable: true },
legendSettings: { visible: true }
},
'#sankey-container'
);<!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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='sankey-container'></div>
</div>
</body>
</html>