Stacked Line Chart in TypeScript Charts
100% Stacked Line
To render a 100% stacked line series in your chart, follow the steps below:
-
Set the series type: Define the series
typeasStackingLine100in your chart configuration. This indicates that the data should be represented as a 100% stacked line chart, with each data series shown as a percentage of the total. This chart type ensures that all lines are stacked to always reach 100% at each data point, allowing for easy comparison of the proportional relationships between the series without the influence of absolute values. -
Inject the StackingLineSeries and Category modules: Use
Chart.Inject(StackingLineSeries, Category)to register theStackingLineSeriesand theCategoryaxis module. TheCategorymodule is required because the x-axis usesvalueType: 'Category'.
import { Chart, Category, Legend, Tooltip, StackingLineSeries } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(StackingLineSeries, Category, Legend, Tooltip);
let chart: Chart = new Chart({
//Initializing Primary X Axis
primaryXAxis: {
interval: 1,
valueType: 'Category'
},
//Initializing Primary Y Axis
primaryYAxis:
{
interval: 20
},
chartArea: { border: { width: 0 } },
//Initializing Chart Series
series: [
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y', name: 'John'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y1', name: 'Peter'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y2', name: 'Steve'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y3', name: 'Charle'
}
],
//Initializing User Interaction Tooltip
tooltip: {
enable: true
}
}, '#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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ x: 'Food', y: 90, y1: 40, y2: 70, y3: 120 },
{ x: 'Transport', y: 80, y1: 90, y2: 110, y3: 70 },
{ x: 'Medical', y: 50, y1: 80, y2: 120, y3: 50 },
{ x: 'Clothes', y: 70, y1: 30, y2: 60, y3: 180 },
{ x: 'Personal Care', y: 30, y1: 80, y2: 80, y3: 30 },
{ x: 'Books', y: 10, y1: 40, y2: 30, y3: 270 },
{ x: 'Fitness', y: 100, y1: 30, y2: 70, y3: 40 },
{ x: 'Electricity', y: 55, y1: 95, y2: 55, y3: 75 },
{ x: 'Tax', y: 20, y1: 50, y2: 40, y3: 65 },
{ x: 'Pet Care', y: 40, y1: 20, y2: 80, y3: 95 },
{ x: 'Education', y: 45, y1: 15, y2: 45, y3: 195 },
{ x: 'Entertainment', y: 75, y1: 45, y2: 65, y3: 115 }
];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, Category, Legend, Tooltip, StackingLineSeries } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(StackingLineSeries, Category, Legend, Tooltip);
let chart: Chart = new Chart({
//Initializing Primary X Axis
primaryXAxis: {
interval: 1,
valueType: 'Category'
},
//Initializing Primary Y Axis
primaryYAxis:
{
interval: 20
},
chartArea: { border: { width: 0 } },
//Initializing Chart Series
series: [
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y', name: 'John'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y1', name: 'Peter'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y2', name: 'Steve'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y3', name: 'Charle'
}
],
//Initializing User Interaction Tooltip
tooltip: {
enable: true
}
}, '#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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ x: 'Food', y: 90, y1: 40, y2: 70, y3: 120 },
{ x: 'Transport', y: 80, y1: 90, y2: 110, y3: 70 },
{ x: 'Medical', y: 50, y1: 80, y2: 120, y3: 50 },
{ x: 'Clothes', y: 70, y1: 30, y2: 60, y3: 180 },
{ x: 'Personal Care', y: 30, y1: 80, y2: 80, y3: 30 },
{ x: 'Books', y: 10, y1: 40, y2: 30, y3: 270 },
{ x: 'Fitness', y: 100, y1: 30, y2: 70, y3: 40 },
{ x: 'Electricity', y: 55, y1: 95, y2: 55, y3: 75 },
{ x: 'Tax', y: 20, y1: 50, y2: 40, y3: 65 },
{ x: 'Pet Care', y: 40, y1: 20, y2: 80, y3: 95 },
{ x: 'Education', y: 45, y1: 15, y2: 45, y3: 195 },
{ x: 'Entertainment', y: 75, y1: 45, y2: 65, y3: 115 }
];Series customization
The following properties can be used to customize the 100% stacked line series.
Solid fill
The fill property determines the color applied to the series.
import { Chart, Category, Legend, Tooltip, StackingLineSeries } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(StackingLineSeries, Category, Legend, Tooltip);
let chart: Chart = new Chart({
//Initializing Primary X Axis
primaryXAxis: {
interval: 1,
valueType: 'Category'
},
//Initializing Primary Y Axis
primaryYAxis:
{
interval: 20
},
chartArea: { border: { width: 0 } },
//Initializing Chart Series
series: [
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y', name: 'John', fill: '#ff4251'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y1', name: 'Peter', fill: '#4C4C4C'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y2', name: 'Steve', fill: '#794F1B'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y3', name: 'Charle', fill: '#1a9a6f'
}
],
//Initializing User Interaction Tooltip
tooltip: {
enable: true
}
}, '#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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>Gradient fill
The fill property also applies an SVG gradient to a 100% stacked line series. Define the gradient within an SVG <defs> element using a unique ID, and assign it to the series in the url(#gradientId) format.
import { Chart, Category, Legend, Tooltip, StackingLineSeries } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(StackingLineSeries, Category, Legend, Tooltip);
let chart: Chart = new Chart({
//Initializing Primary X Axis
primaryXAxis: {
interval: 1,
valueType: 'Category'
},
//Initializing Primary Y Axis
primaryYAxis:
{
interval: 20
},
chartArea: { border: { width: 0 } },
//Initializing Chart Series
series: [
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y', name: 'John', fill: 'url(#gradient1)'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y1', name: 'Peter', fill: 'url(#gradient2)'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y2', name: 'Steve', fill: 'url(#gradient3)'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y3', name: 'Charle', fill: 'url(#gradient4)'
}
],
//Initializing User Interaction Tooltip
tooltip: {
enable: true
}
}, '#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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
<svg style="width:1px; height:1px">
<defs>
<linearGradient id="gradient1">
<stop offset="0%" style="stop-color:coral;stop-opacity:5" />
<stop offset="50%" style="stop-color:mediumseagreen;stop-opacity:5" />
</linearGradient>
</defs>
</svg>
<svg style="width:1px; height:1px">
<defs>
<linearGradient id="gradient2">
<stop offset="0%" style="stop-color:darkred;stop-opacity:5" />
<stop offset="50%" style="stop-color:darkorange;stop-opacity:5" />
</linearGradient>
</defs>
</svg>
<svg style="width:1px; height:1px">
<defs>
<linearGradient id="gradient3">
<stop offset="0%" style="stop-color:darkmagenta;stop-opacity:5" />
<stop offset="50%" style="stop-color:darkcyan;stop-opacity:5" />
</linearGradient>
</defs>
</svg>
<svg style="width:1px; height:1px">
<defs>
<linearGradient id="gradient4">
<stop offset="0%" style="stop-color:darkviolet;stop-opacity:5" />
<stop offset="50%" style="stop-color:darkgoldenrod;stop-opacity:5" />
</linearGradient>
</defs>
</svg>
</body>
</html>export let chartData: Object[] = [
{ x: 'Food', y: 90, y1: 40, y2: 70, y3: 120 },
{ x: 'Transport', y: 80, y1: 90, y2: 110, y3: 70 },
{ x: 'Medical', y: 50, y1: 80, y2: 120, y3: 50 },
{ x: 'Clothes', y: 70, y1: 30, y2: 60, y3: 180 },
{ x: 'Personal Care', y: 30, y1: 80, y2: 80, y3: 30 },
{ x: 'Books', y: 10, y1: 40, y2: 30, y3: 270 },
{ x: 'Fitness', y: 100, y1: 30, y2: 70, y3: 40 },
{ x: 'Electricity', y: 55, y1: 95, y2: 55, y3: 75 },
{ x: 'Tax', y: 20, y1: 50, y2: 40, y3: 65 },
{ x: 'Pet Care', y: 40, y1: 20, y2: 80, y3: 95 },
{ x: 'Education', y: 45, y1: 15, y2: 45, y3: 195 },
{ x: 'Entertainment', y: 75, y1: 45, y2: 65, y3: 115 }
];Opacity
The opacity property controls the transparency of the fill and affects how the series blends with background or overlapping series.
import { Chart, Category, Legend, Tooltip, StackingLineSeries } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(StackingLineSeries, Category, Legend, Tooltip);
let chart: Chart = new Chart({
//Initializing Primary X Axis
primaryXAxis: {
interval: 1,
valueType: 'Category'
},
//Initializing Primary Y Axis
primaryYAxis:
{
interval: 20
},
chartArea: { border: { width: 0 } },
//Initializing Chart Series
series: [
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y', name: 'John', opacity: 0.7
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y1', name: 'Peter', opacity: 0.7
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y2', name: 'Steve', opacity: 0.7
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y3', name: 'Charle', opacity: 0.7
}
],
//Initializing User Interaction Tooltip
tooltip: {
enable: true
}
}, '#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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ x: 'Food', y: 90, y1: 40, y2: 70, y3: 120 },
{ x: 'Transport', y: 80, y1: 90, y2: 110, y3: 70 },
{ x: 'Medical', y: 50, y1: 80, y2: 120, y3: 50 },
{ x: 'Clothes', y: 70, y1: 30, y2: 60, y3: 180 },
{ x: 'Personal Care', y: 30, y1: 80, y2: 80, y3: 30 },
{ x: 'Books', y: 10, y1: 40, y2: 30, y3: 270 },
{ x: 'Fitness', y: 100, y1: 30, y2: 70, y3: 40 },
{ x: 'Electricity', y: 55, y1: 95, y2: 55, y3: 75 },
{ x: 'Tax', y: 20, y1: 50, y2: 40, y3: 65 },
{ x: 'Pet Care', y: 40, y1: 20, y2: 80, y3: 95 },
{ x: 'Education', y: 45, y1: 15, y2: 45, y3: 195 },
{ x: 'Entertainment', y: 75, y1: 45, y2: 65, y3: 115 }
];Dash array
The dashArray property determines the pattern of dashes and gaps in the series.
import { Chart, Category, Legend, Tooltip, StackingLineSeries } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(StackingLineSeries, Category, Legend, Tooltip);
let chart: Chart = new Chart({
//Initializing Primary X Axis
primaryXAxis: {
interval: 1,
valueType: 'Category'
},
//Initializing Primary Y Axis
primaryYAxis:
{
interval: 20
},
chartArea: { border: { width: 0 } },
//Initializing Chart Series
series: [
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y', name: 'John', dashArray: '5,5'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y1', name: 'Peter', dashArray: '5,5'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y2', name: 'Steve', dashArray: '5,5'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y3', name: 'Charle', dashArray: '5,5'
}
],
//Initializing User Interaction Tooltip
tooltip: {
enable: true
}
}, '#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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ x: 'Food', y: 90, y1: 40, y2: 70, y3: 120 },
{ x: 'Transport', y: 80, y1: 90, y2: 110, y3: 70 },
{ x: 'Medical', y: 50, y1: 80, y2: 120, y3: 50 },
{ x: 'Clothes', y: 70, y1: 30, y2: 60, y3: 180 },
{ x: 'Personal Care', y: 30, y1: 80, y2: 80, y3: 30 },
{ x: 'Books', y: 10, y1: 40, y2: 30, y3: 270 },
{ x: 'Fitness', y: 100, y1: 30, y2: 70, y3: 40 },
{ x: 'Electricity', y: 55, y1: 95, y2: 55, y3: 75 },
{ x: 'Tax', y: 20, y1: 50, y2: 40, y3: 65 },
{ x: 'Pet Care', y: 40, y1: 20, y2: 80, y3: 95 },
{ x: 'Education', y: 45, y1: 15, y2: 45, y3: 195 },
{ x: 'Entertainment', y: 75, y1: 45, y2: 65, y3: 115 }
];Width
The width property specifies the stroke width applied to the series.
import { Chart, Category, Legend, Tooltip, StackingLineSeries } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(StackingLineSeries, Category, Legend, Tooltip);
let chart: Chart = new Chart({
//Initializing Primary X Axis
primaryXAxis: {
interval: 1,
valueType: 'Category'
},
//Initializing Primary Y Axis
primaryYAxis:
{
interval: 20
},
chartArea: { border: { width: 0 } },
//Initializing Chart Series
series: [
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y', name: 'John', width: 2
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y1', name: 'Peter', width: 2
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y2', name: 'Steve', width: 2
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y3', name: 'Charle', width: 2
}
],
//Initializing User Interaction Tooltip
tooltip: {
enable: true
}
}, '#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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ x: 'Food', y: 90, y1: 40, y2: 70, y3: 120 },
{ x: 'Transport', y: 80, y1: 90, y2: 110, y3: 70 },
{ x: 'Medical', y: 50, y1: 80, y2: 120, y3: 50 },
{ x: 'Clothes', y: 70, y1: 30, y2: 60, y3: 180 },
{ x: 'Personal Care', y: 30, y1: 80, y2: 80, y3: 30 },
{ x: 'Books', y: 10, y1: 40, y2: 30, y3: 270 },
{ x: 'Fitness', y: 100, y1: 30, y2: 70, y3: 40 },
{ x: 'Electricity', y: 55, y1: 95, y2: 55, y3: 75 },
{ x: 'Tax', y: 20, y1: 50, y2: 40, y3: 65 },
{ x: 'Pet Care', y: 40, y1: 20, y2: 80, y3: 95 },
{ x: 'Education', y: 45, y1: 15, y2: 45, y3: 195 },
{ x: 'Entertainment', y: 75, y1: 45, y2: 65, y3: 115 }
];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.
import { Chart, Category, Legend, Tooltip, StackingLineSeries } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(StackingLineSeries, Category, Legend, Tooltip);
let chart: Chart = new Chart({
//Initializing Primary X Axis
primaryXAxis: {
interval: 1,
valueType: 'Category'
},
//Initializing Primary Y Axis
primaryYAxis:
{
interval: 20
},
chartArea: { border: { width: 0 } },
//Initializing Chart Series
series: [
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true, width: 7, height: 7, isFilled: true },
xName: 'x', yName: 'y', name: 'John', width: 2,
emptyPointSettings: { mode: 'Average' }
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true, width: 7, height: 7, isFilled: true },
xName: 'x', yName: 'y1', name: 'Peter', width: 2
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true, width: 7, height: 7, isFilled: true },
xName: 'x', yName: 'y2', name: 'Steve', width: 2,
emptyPointSettings: { mode: 'Gap' }
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true, width: 7, height: 7, isFilled: true },
xName: 'x', yName: 'y3', name: 'Charle', width: 2
}
],
//Initializing User Interaction Tooltip
tooltip: {
enable: true
}
}, '#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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ x: 'Food', y: 90, y1: 40, y2: 70, y3: 120 },
{ x: 'Transport', y: 80, y1: 90, y2: 110, y3: 70 },
{ x: 'Medical', y: 50, y1: 80, y2: 120, y3: 50 },
{ x: 'Clothes', y: null, y1: 30, y2: 60, y3: 180 },
{ x: 'Personal Care', y: 30, y1: 80, y2: 80, y3: 30 },
{ x: 'Books', y: 10, y1: 40, y2: 30, y3: 270 },
{ x: 'Fitness', y: 100, y1: 30, y2: 70, y3: 40 },
{ x: 'Electricity', y: 55, y1: 95, y2: undefined, y3: 75 },
{ x: 'Tax', y: 20, y1: 50, y2: 40, y3: 65 },
{ x: 'Pet Care', y: 40, y1: 20, y2: 80, y3: 95 },
{ x: 'Education', y: 45, y1: 15, y2: 45, y3: 195 },
{ x: 'Entertainment', y: 75, y1: 45, y2: 65, y3: 115 }
];Fill
Use the fill property to set the fill color for empty points.
import { Chart, Category, Legend, Tooltip, StackingLineSeries } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(StackingLineSeries, Category, Legend, Tooltip);
let chart: Chart = new Chart({
//Initializing Primary X Axis
primaryXAxis: {
interval: 1,
valueType: 'Category'
},
//Initializing Primary Y Axis
primaryYAxis:
{
interval: 20
},
chartArea: { border: { width: 0 } },
//Initializing Chart Series
series: [
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true, width: 7, height: 7, isFilled: true },
xName: 'x', yName: 'y', name: 'John', width: 2,
emptyPointSettings: { mode: 'Average', fill: 'red' }
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true, width: 7, height: 7, isFilled: true },
xName: 'x', yName: 'y1', name: 'Peter', width: 2
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true, width: 7, height: 7, isFilled: true },
xName: 'x', yName: 'y2', name: 'Steve', width: 2,
emptyPointSettings: { mode: 'Gap' }
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true, width: 7, height: 7, isFilled: true },
xName: 'x', yName: 'y3', name: 'Charle', width: 2
}
],
//Initializing User Interaction Tooltip
tooltip: {
enable: true
}
}, '#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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ x: 'Food', y: 90, y1: 40, y2: 70, y3: 120 },
{ x: 'Transport', y: 80, y1: 90, y2: 110, y3: 70 },
{ x: 'Medical', y: 50, y1: 80, y2: 120, y3: 50 },
{ x: 'Clothes', y: null, y1: 30, y2: 60, y3: 180 },
{ x: 'Personal Care', y: 30, y1: 80, y2: 80, y3: 30 },
{ x: 'Books', y: 10, y1: 40, y2: 30, y3: 270 },
{ x: 'Fitness', y: 100, y1: 30, y2: 70, y3: 40 },
{ x: 'Electricity', y: 55, y1: 95, y2: undefined, y3: 75 },
{ x: 'Tax', y: 20, y1: 50, y2: 40, y3: 65 },
{ x: 'Pet Care', y: 40, y1: 20, y2: 80, y3: 95 },
{ x: 'Education', y: 45, y1: 15, y2: 45, y3: 195 },
{ x: 'Entertainment', y: 75, y1: 45, y2: 65, y3: 115 }
];Border
Use the border property to customize the border width and color for empty points.
import { Chart, Category, Legend, Tooltip, StackingLineSeries } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(StackingLineSeries, Category, Legend, Tooltip);
let chart: Chart = new Chart({
//Initializing Primary X Axis
primaryXAxis: {
interval: 1,
valueType: 'Category'
},
//Initializing Primary Y Axis
primaryYAxis:
{
interval: 20
},
chartArea: { border: { width: 0 } },
//Initializing Chart Series
series: [
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true, width: 7, height: 7, isFilled: true },
xName: 'x', yName: 'y', name: 'John', width: 2,
emptyPointSettings: { mode: 'Average', fill: 'red', border: { width: 2, color: 'green' } }
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true, width: 7, height: 7, isFilled: true },
xName: 'x', yName: 'y1', name: 'Peter', width: 2
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true, width: 7, height: 7, isFilled: true },
xName: 'x', yName: 'y2', name: 'Steve', width: 2,
emptyPointSettings: { mode: 'Gap' }
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true, width: 7, height: 7, isFilled: true },
xName: 'x', yName: 'y3', name: 'Charle', width: 2
}
],
//Initializing User Interaction Tooltip
tooltip: {
enable: true
}
}, '#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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ x: 'Food', y: 90, y1: 40, y2: 70, y3: 120 },
{ x: 'Transport', y: 80, y1: 90, y2: 110, y3: 70 },
{ x: 'Medical', y: 50, y1: 80, y2: 120, y3: 50 },
{ x: 'Clothes', y: null, y1: 30, y2: 60, y3: 180 },
{ x: 'Personal Care', y: 30, y1: 80, y2: 80, y3: 30 },
{ x: 'Books', y: 10, y1: 40, y2: 30, y3: 270 },
{ x: 'Fitness', y: 100, y1: 30, y2: 70, y3: 40 },
{ x: 'Electricity', y: 55, y1: 95, y2: undefined, y3: 75 },
{ x: 'Tax', y: 20, y1: 50, y2: 40, y3: 65 },
{ x: 'Pet Care', y: 40, y1: 20, y2: 80, y3: 95 },
{ x: 'Education', y: 45, y1: 15, y2: 45, y3: 195 },
{ x: 'Entertainment', y: 75, y1: 45, y2: 65, y3: 115 }
];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.
import { Chart, Category, Legend, Tooltip, StackingLineSeries, ISeriesRenderEventArgs } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(StackingLineSeries, Category, Legend, Tooltip);
let chart: Chart = new Chart({
//Initializing Primary X Axis
primaryXAxis: {
interval: 1,
valueType: 'Category'
},
//Initializing Primary Y Axis
primaryYAxis:
{
interval: 20
},
chartArea: { border: { width: 0 } },
//Initializing Chart Series
series: [
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y', name: 'John', width: 2
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y1', name: 'Peter', width: 2
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y2', name: 'Steve', width: 2
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y3', name: 'Charle', width: 2
}
],
//Initializing User Interaction Tooltip
tooltip: {
enable: true
},
seriesRender: (args: ISeriesRenderEventArgs) => {
if (args.series.index === 0) {
args.fill = '#ff4251';
}
else if (args.series.index === 1) {
args.fill = '#4C4C4C';
}
else if (args.series.index === 2) {
args.fill = '#794F1B';
}
else if (args.series.index === 3) {
args.fill = '#1a9a6f';
}
}
}, '#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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ x: 'Food', y: 90, y1: 40, y2: 70, y3: 120 },
{ x: 'Transport', y: 80, y1: 90, y2: 110, y3: 70 },
{ x: 'Medical', y: 50, y1: 80, y2: 120, y3: 50 },
{ x: 'Clothes', y: 70, y1: 30, y2: 60, y3: 180 },
{ x: 'Personal Care', y: 30, y1: 80, y2: 80, y3: 30 },
{ x: 'Books', y: 10, y1: 40, y2: 30, y3: 270 },
{ x: 'Fitness', y: 100, y1: 30, y2: 70, y3: 40 },
{ x: 'Electricity', y: 55, y1: 95, y2: 55, y3: 75 },
{ x: 'Tax', y: 20, y1: 50, y2: 40, y3: 65 },
{ x: 'Pet Care', y: 40, y1: 20, y2: 80, y3: 95 },
{ x: 'Education', y: 45, y1: 15, y2: 45, y3: 195 },
{ x: 'Entertainment', y: 75, y1: 45, y2: 65, y3: 115 }
];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.
import { Chart, Category, Legend, Tooltip, StackingLineSeries, IPointRenderEventArgs } from '@syncfusion/ej2-charts';
import { chartData } from './datasource.ts';
Chart.Inject(StackingLineSeries, Category, Legend, Tooltip);
let chart: Chart = new Chart({
//Initializing Primary X Axis
primaryXAxis: {
interval: 1,
valueType: 'Category'
},
//Initializing Primary Y Axis
primaryYAxis:
{
interval: 20
},
chartArea: { border: { width: 0 } },
//Initializing Chart Series
series: [
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y', name: 'John', width: 2
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y1', name: 'Peter', width: 2
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y2', name: 'Steve', width: 2
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
xName: 'x', yName: 'y3', name: 'Charle', width: 2
}
],
//Initializing User Interaction Tooltip
tooltip: {
enable: true
},
pointRender: (args: IPointRenderEventArgs) => {
if (args.point.y < 70) {
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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let chartData: Object[] = [
{ x: 'Food', y: 90, y1: 40, y2: 70, y3: 120 },
{ x: 'Transport', y: 80, y1: 90, y2: 110, y3: 70 },
{ x: 'Medical', y: 50, y1: 80, y2: 120, y3: 50 },
{ x: 'Clothes', y: 70, y1: 30, y2: 60, y3: 180 },
{ x: 'Personal Care', y: 30, y1: 80, y2: 80, y3: 30 },
{ x: 'Books', y: 10, y1: 40, y2: 30, y3: 270 },
{ x: 'Fitness', y: 100, y1: 30, y2: 70, y3: 40 },
{ x: 'Electricity', y: 55, y1: 95, y2: 55, y3: 75 },
{ x: 'Tax', y: 20, y1: 50, y2: 40, y3: 65 },
{ x: 'Pet Care', y: 40, y1: 20, y2: 80, y3: 95 },
{ x: 'Education', y: 45, y1: 15, y2: 45, y3: 195 },
{ x: 'Entertainment', y: 75, y1: 45, y2: 65, y3: 115 }
];Troubleshooting
The following list describes common issues you may encounter when working with the 100% Stacked Line series and how to resolve them.
Chart does not render a 100% stacked line: Confirm the type property of each series is set to StackingLine100. If type is omitted or set to a different value (for example, StackingLine), the data is drawn as overlapping (non-normalized) lines. Also ensure StackingLineSeries (plus Category, Legend, and Tooltip if used) is registered with Chart.Inject(...) before the chart is initialized, or import the modules directly from @syncfusion/ej2-charts using ES module syntax.
Bands do not normalize to 100%: 100% stacked series render each x-position as 100% of all contributing values. If percentages do not sum to 100, verify that each series shares the same xName and that the input data is non-negative. Negative values are not normalized and will produce inconsistent percentages.