Appearance in JavaScript Sankey Chart component
18 Nov 201822 minutes to read
The Sankey Chart provides comprehensive customization options to control visual appearance, dimensions, responsiveness, colors, borders, and themes. These appearance settings enable you to create diagrams that match your application’s design system and user experience requirements.
This guide covers dimension configuration, responsive sizing, backgrounds, borders, margins, and theme selection.
Dimensions
Control the size of the Sankey Chart using the width and height properties. You can specify dimensions in pixels (px) or percentages (%) to create fixed or responsive layouts.
Width and Height Properties
| Property | Type | Default | Description |
|---|---|---|---|
| width | string | null | Width of the chart as a CSS value (e.g., ‘700px’ or ‘100%’). |
| height | string | null | Height of the chart as a CSS value (e.g., ‘420px’ or ‘100%’). |
const nodes = [
{ id: 'Agricultural Waste' },
{ id: 'Biomass Residues' },
{ id: 'Bio-conversion' },
{ id: 'Liquid Biofuel' },
{ id: 'Electricity' },
{ id: 'Heat' }
];
const links = [
{ 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 = new ej.charts.Sankey(
{
width: '800px',
height: '600px',
margin: { left: 40, right: 40, top: 40, bottom: 40 },
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://cdn.syncfusion.com/ej2/34.1.29/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="sankey-container"></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>Responsive Sizing
Use percentage-based dimensions for responsive layouts that adapt to container sizes. This is recommended for applications that need to work across different device sizes and screen orientations:
const nodes = [
{ id: 'Agricultural Waste' },
{ id: 'Biomass Residues' },
{ id: 'Bio-conversion' },
{ id: 'Liquid Biofuel' },
{ id: 'Electricity' },
{ id: 'Heat' }
];
const links = [
{ 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 = new ej.charts.Sankey(
{
width: '90%',
height: ej.base.Browser.isDevice ? '600px' : '450px',
margin: { left: ej.base.Browser.isDevice ? 10 : 40, right: ej.base.Browser.isDevice ? 10 : 40, top: 20, bottom: 20 },
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://cdn.syncfusion.com/ej2/34.1.29/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="sankey-container"></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>Background Customization
Customize the background of the Sankey Chart with solid colors or background images to match your application’s theme or create specific visual effects.
Background Properties
| Property | Type | Default | Description |
|---|---|---|---|
| background | string | null | Background color of the chart (CSS color value). |
| backgroundImage | string | null | Background image URL. |
const nodes = [
{ id: 'Agricultural Waste' },
{ id: 'Biomass Residues' },
{ id: 'Bio-conversion' },
{ id: 'Liquid Biofuel' },
{ id: 'Electricity' },
{ id: 'Heat' }
];
const links = [
{ 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 = new ej.charts.Sankey(
{
width: '90%',
height: '450px',
background: '#f0f0f0',
nodes: nodes,
links: links
},
'#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://cdn.syncfusion.com/ej2/34.1.29/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="sankey-container"></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 Customization
Customize the border of the Sankey Chart container.
Border Properties
| Property | Type | Default | Description |
|---|---|---|---|
| border.color | string | ’’ | Border color. Accepts values in hex or RGBA as valid CSS color strings. |
| border.width | number | 1 | Border width in pixels. |
| border.dashArray | string | ’’ | Sets the length of dashes in the stroke of border. |
const nodes = [
{ id: 'Agricultural Waste' },
{ id: 'Biomass Residues' },
{ id: 'Bio-conversion' },
{ id: 'Liquid Biofuel' },
{ id: 'Electricity' },
{ id: 'Heat' }
];
const links = [
{ 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 = new ej.charts.Sankey(
{
width: '90%',
height: '450px',
border: { color: '#333', width: 2 },
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://cdn.syncfusion.com/ej2/34.1.29/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="sankey-container"></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>Margin Customization
Control the spacing around the chart content using margins.
Margin Properties
| Property | Type | Default | Description |
|---|---|---|---|
| margin.left | number | 10 | Left margin in pixels. |
| margin.right | number | 10 | Right margin in pixels. |
| margin.top | number | 10 | Top margin in pixels. |
| margin.bottom | number | 10 | Bottom margin in pixels. |
const nodes = [
{ id: 'Agricultural Waste' },
{ id: 'Biomass Residues' },
{ id: 'Bio-conversion' },
{ id: 'Liquid Biofuel' },
{ id: 'Electricity' },
{ id: 'Heat' }
];
const links = [
{ 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 = new ej.charts.Sankey(
{
width: '90%',
height: '450px',
margin: { left: 50, right: 50, top: 50, bottom: 50 },
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://cdn.syncfusion.com/ej2/34.1.29/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="sankey-container"></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>Theme
The Sankey Chart provides multiple built-in themes to customize the visual appearance. Apply a theme using the theme property.
Theme Configuration
const nodes = [
{ id: 'Agricultural Waste' },
{ id: 'Biomass Residues' },
{ id: 'Bio-conversion' },
{ id: 'Liquid Biofuel' },
{ id: 'Electricity' },
{ id: 'Heat' }
];
const links = [
{ 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 = new ej.charts.Sankey(
{
width: '90%',
height: '450px',
theme: 'Tailwind',
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://cdn.syncfusion.com/ej2/34.1.29/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="sankey-container"></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>