Title and Subtitle in TypeScript Sankey Chart component
18 Nov 201815 minutes to read
The Sankey Chart supports adding descriptive titles and subtitles to provide context and information about your data visualization. These text elements help users quickly understand the purpose and content of the diagram. You can fully customize the text, styling, alignment, and appearance using dedicated properties.
This guide covers title and subtitle configuration, styling options, and best practices for effective diagram labeling.
Title and Subtitle Properties
| Property | Type | Description |
|---|---|---|
| title | string | The main title text displayed at the top of the chart. |
| subTitle | string | The subtitle text displayed below the main title. |
| titleStyle | object | Styling options for the title text. |
| subTitleStyle | object | Styling options for the subtitle text. |
Title/Subtitle Style Properties
Both titleStyle and subTitleStyle support the following properties:
| Property | Type | Default | Description |
|---|---|---|---|
| size | string | null | Font size for the text. |
| fontWeight | string | null | Font weight (e.g., ‘400’, ‘700’). |
| fontFamily | string | null | Font family name. |
| color | string | null | Text color. |
| fontStyle | string | ‘normal’ | Font style (‘normal’ or ‘italic’). |
| opacity | number | 1 | Text opacity (0 to 1). |
| textAlignment | string | ‘Center’ | Text alignment (‘Left’, ‘Center’, ‘Right’). |
Basic Title and Subtitle
Add a main title and descriptive subtitle to your Sankey Chart to provide context about the data visualization:
import { Sankey, SankeyNodeModel, SankeyLinkModel, SankeyTooltip, SankeyLegend, SankeyExport } 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 sankey: Sankey = new Sankey(
{
width: '90%',
height: '450px',
title: 'Energy Flow Diagram',
subTitle: 'Agricultural Energy Conversion',
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>Customized Title and Subtitle Styling
Apply custom styling to both the title and subtitle including font properties, colors, alignment, and opacity to match your design requirements:
import { Sankey, SankeyNodeModel, SankeyLinkModel, SankeyTooltip, SankeyLegend, SankeyExport, SankeyTitleStyleModel } from '@syncfusion/ej2-charts';
Sankey.Inject(SankeyTooltip, SankeyLegend, SankeyExport);
const titleStyle: SankeyTitleStyleModel = {
fontFamily: 'Arial',
fontStyle: 'italic',
fontWeight: 'bold',
size: '18px',
color: '#1F77B4'
};
const subtitleStyle: SankeyTitleStyleModel = {
fontFamily: 'Arial',
fontStyle: 'normal',
fontWeight: 'normal',
size: '14px',
color: '#FF7F0E'
};
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 sankey: Sankey = new Sankey(
{
width: '90%',
height: '450px',
title: 'Energy Flow Diagram',
subTitle: 'Agricultural Energy Conversion',
titleStyle: titleStyle,
subTitleStyle: subtitleStyle,
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>Title Only (Without Subtitle)
Add only a title to the Sankey Chart when a subtitle is not needed. This provides a clean, minimal header for your visualization:
import { Sankey, SankeyNodeModel, SankeyLinkModel, SankeyTooltip, SankeyLegend, SankeyExport } 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 sankey: Sankey = new Sankey(
{
width: '90%',
height: '450px',
title: 'Energy Flow Diagram',
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>Title with Different Alignments
Control the alignment of title and subtitle text:
import { Sankey, SankeyNodeModel, SankeyLinkModel, SankeyTooltip, SankeyLegend, SankeyTitleStyleModel } from '@syncfusion/ej2-charts';
Sankey.Inject(SankeyTooltip, SankeyLegend);
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 titleStyle: SankeyTitleStyleModel = { textAlignment: 'Near' };
const subtitleStyle: SankeyTitleStyleModel = { textAlignment: 'Center' };
const sankey: Sankey = new Sankey(
{
width: '90%',
height: '450px',
title: 'Energy Flow Diagram',
subTitle: 'Agricultural Energy Conversion',
titleStyle: titleStyle,
subTitleStyle: subtitleStyle ,
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>Title Best Practices
- Descriptive: Use clear, descriptive titles that explain what the chart shows
- Concise: Keep titles brief and to the point
- Hierarchy: Make the title larger and bolder than the subtitle for visual hierarchy
- Readability: Ensure sufficient contrast between text color and background
- Font Choice: Use readable fonts like Segoe UI, Arial, or Verdana