Stacked Bar Chart in TypeScript Charts
100% Stacked Bar
To render a 100% stacked bar series in your chart, follow the steps below:
-
Inject the StackingBarSeries module: Use the
Chart.Inject(StackingBarSeries)method to inject theStackingBarSeriesmodule into your chart. The control is initialized with the remaining configuration in the next step. -
Inject the StackingBarSeries module: Use the
Chart.Inject(StackingBarSeries)method to inject theStackingBarSeriesmodule into your chart. This step is essential, as it ensures that the necessary functionalities for rendering the 100% stacked bar series are available in your chart.
import { Chart, StackingBarSeries } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingBarSeries);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Months'
},
primaryYAxis:
{
title: 'Percentage (%)',
labelFormat: '{value}%'
},
series: [
{
//Series type as 100% stacked bar
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y',
name: 'Apple'
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y1',
name: 'Orange'
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y2',
name: 'Wastage'
}
],
title: 'Sales Comparison'
}, '#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 stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];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, StackingBarSeries } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingBarSeries);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Months'
},
primaryYAxis:
{
title: 'Percentage (%)',
labelFormat: '{value}%'
},
series: [
{
//Series type as 100% stacked bar
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y',
name: 'Apple'
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y1',
name: 'Orange'
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y2',
name: 'Wastage'
}
],
title: 'Sales Comparison'
}, '#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 stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];Series customization
The following properties can be used to customize the 100% stacked bar series.
Solid fill
The fill property determines the color applied to the series.
import { Chart, StackingBarSeries } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingBarSeries);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Months'
},
primaryYAxis:
{
title: 'Percentage (%)',
labelFormat: '{value}%'
},
series: [
{
//Series type as 100% stacked bar
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y',
name: 'Apple',
fill: '#483D8B'
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y1',
name: 'Orange',
fill: '#556B2F'
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y2',
name: 'Wastage',
fill: '#8B0000'
}
],
title: 'Sales Comparison'
}, '#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 stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];Gradient fill
The fill property also applies an SVG gradient to a 100% stacked bar 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, StackingBarSeries } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingBarSeries);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Months'
},
primaryYAxis:
{
title: 'Percentage (%)',
labelFormat: '{value}%'
},
series: [
{
//Series type as 100% stacked bar
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y',
name: 'Apple',
fill: 'url(#gradient1)'
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y1',
name: 'Orange',
fill: 'url(#gradient2)'
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y2',
name: 'Wastage',
fill: 'url(#gradient3)'
}
],
title: 'Sales Comparison'
}, '#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>
</body>
</html>export let stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];Opacity
The opacity property controls the transparency of the fill and affects how the series blends with background or overlapping series.
import { Chart, StackingBarSeries } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingBarSeries);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Months'
},
primaryYAxis:
{
title: 'Percentage (%)',
labelFormat: '{value}%'
},
series: [
{
//Series type as 100% stacked bar
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y',
name: 'Apple',
opacity: 0.7
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y1',
name: 'Orange',
opacity: 0.7
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y2',
name: 'Wastage',
opacity: 0.7
}
],
title: 'Sales Comparison'
}, '#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 stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];Border
Use the border property to configure the border width, color, and dash array of the 100% stacked bar series.
import { Chart, StackingBarSeries } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingBarSeries);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Months'
},
primaryYAxis:
{
title: 'Percentage (%)',
labelFormat: '{value}%'
},
series: [
{
//Series type as 100% stacked bar
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y',
name: 'Apple',
border: { width: 2, color: '#ff4251', dashArray: '5,5' }
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y1',
name: 'Orange',
border: { width: 2, color: '#66BDB7', dashArray: '5,5' }
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y2',
name: 'Wastage',
border: { width: 2, color: '#794F1B', dashArray: '5,5' }
}
],
title: 'Sales Comparison'
}, '#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 stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];100% Cylindrical stacked bar chart
To render a 100% cylindrical stacked bar chart, set the columnFacet property to Cylinder in the chart series. The only other valid value is Rectangle (the default), which renders rectangular bars.
import { Chart, StackingBarSeries } from '@syncfusion/ej2-charts';
import { cylindricalData } from './datasource.ts';
Chart.Inject(StackingBarSeries);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Months'
},
primaryYAxis:
{
title: 'Percentage (%)',
labelFormat: '{value}%'
},
series: [
{
//Series type as 100% stacked bar with cylindrical shape
type: 'StackingBar100',
columnFacet: 'Cylinder',
dataSource: cylindricalData,
xName: 'x',
yName: 'y',
name: 'Apple'
},
{
type: 'StackingBar100',
columnFacet: 'Cylinder',
dataSource: cylindricalData,
xName: 'x',
yName: 'y1',
name: 'Orange'
},
{
type: 'StackingBar100',
columnFacet: 'Cylinder',
dataSource: cylindricalData,
xName: 'x',
yName: 'y2',
name: 'Wastage'
}
],
title: 'Sales Comparison'
}, '#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 cylindricalData: Object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];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, StackingBarSeries } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingBarSeries);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Months'
},
primaryYAxis:
{
title: 'Percentage (%)',
labelFormat: '{value}%'
},
series: [
{
//Series type as 100% stacked bar
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y',
name: 'Apple',
emptyPointSettings: {
mode: 'Zero'
}
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y1',
name: 'Orange',
emptyPointSettings: {
mode: 'Gap'
}
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y2',
name: 'Wastage',
emptyPointSettings: {
mode: 'Average'
}
}
],
title: 'Sales Comparison'
}, '#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 stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: null },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: undefined, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: null, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];Fill
Use the fill property to set the fill color for empty points.
import { Chart, StackingBarSeries } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingBarSeries);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Months'
},
primaryYAxis:
{
title: 'Percentage (%)',
labelFormat: '{value}%'
},
series: [
{
//Series type as 100% stacked bar
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y',
name: 'Apple',
emptyPointSettings: {
mode: 'Zero'
}
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y1',
name: 'Orange',
emptyPointSettings: {
mode: 'Gap'
}
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y2',
name: 'Wastage',
emptyPointSettings: {
mode: 'Average',
fill: 'red'
}
}
],
title: 'Sales Comparison'
}, '#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 stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: null },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: undefined, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: null, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];Border
Use the border property to customize the border width and color for empty points.
import { Chart, StackingBarSeries } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingBarSeries);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Months'
},
primaryYAxis:
{
title: 'Percentage (%)',
labelFormat: '{value}%'
},
series: [
{
//Series type as 100% stacked bar
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y',
name: 'Apple',
emptyPointSettings: {
mode: 'Zero'
}
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y1',
name: 'Orange',
emptyPointSettings: {
mode: 'Gap'
}
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y2',
name: 'Wastage',
emptyPointSettings: {
mode: 'Average',
fill: 'red',
border: { width: 2, color: 'green' }
}
}
],
title: 'Sales Comparison'
}, '#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 stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: null },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: undefined, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: null, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];Corner radius
The cornerRadius property in the chart series is used to customize the corner radius for 100% stacked bar series. This allows you to create 100% stacked bars with rounded corners. You can customize each corner of the 100% stacked bars using the topLeft, topRight, bottomLeft, and bottomRight properties.
import { Chart, StackingBarSeries, IPointRenderEventArgs } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingBarSeries);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Months'
},
primaryYAxis:
{
title: 'Percentage (%)',
labelFormat: '{value}%'
},
series: [
{
//Series type as 100% stacked bar
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y',
name: 'Apple'
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y1',
name: 'Orange'
},
{ cornerRadius: { topRight: 10, bottomRight: 10 },
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y2',
name: 'Wastage'
}
],
title: 'Sales Comparison',
pointRender: (args: IPointRenderEventArgs) => {
if (args.point.series.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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];Point corner radius
You 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, StackingBarSeries, IPointRenderEventArgs } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingBarSeries);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Years'
},
primaryYAxis:
{
title: 'Percentage (%)',
labelFormat: '{value}%'
},
series: [
{
//Series type as 100% stacked bar
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y',
name: 'Apple'
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y1',
name: 'Orange'
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y2',
name: 'Wastage'
}
],
title: 'Sales Comparison',
pointRender: (args: IPointRenderEventArgs) => {
if (args.point.index === 1 && args.point.series.index === 2) {
args.cornerRadius = { topLeft: 0, bottomLeft: 0, topRight: 10, bottomRight: 10 };
}
if (args.point.index === 4 && args.point.series.index === 2) {
args.cornerRadius = { topLeft: 0, bottomLeft: 0, topRight: 10, bottomRight: 10 };
}
if (args.point.index === 6 && args.point.series.index === 2) {
args.cornerRadius = { topLeft: 0, bottomLeft: 0, topRight: 10, bottomRight: 10 };
}
if (args.point.index === 8 && args.point.series.index === 2) {
args.cornerRadius = { topLeft: 0, bottomLeft: 0, topRight: 10, bottomRight: 10 };
}
}
}, '#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 stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];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, StackingBarSeries, ISeriesRenderEventArgs } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingBarSeries);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Months'
},
primaryYAxis:
{
title: 'Percentage (%)',
labelFormat: '{value}%'
},
series: [
{
//Series type as 100% stacked bar
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y',
name: 'Apple'
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y1',
name: 'Orange'
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y2',
name: 'Wastage'
}
],
title: 'Sales Comparison',
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';
}
}
}, '#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 stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];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, StackingBarSeries, IPointRenderEventArgs } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingBarSeries);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Months'
},
primaryYAxis:
{
title: 'Percentage (%)',
labelFormat: '{value}%'
},
series: [
{
//Series type as 100% stacked bar
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y',
name: 'Apple'
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y1',
name: 'Orange'
},
{
type: 'StackingBar100',
dataSource: stackedData,
xName: 'x',
yName: 'y2',
name: 'Wastage'
}
],
title: 'Sales Comparison',
pointRender: (args: IPointRenderEventArgs) => {
if (args.point.series.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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>export let stackedData: object[] = [
{ x: 2000, y: 0.61, y1: 0.03, y2: 0.48},
{ x: 2001, y: 0.81, y1: 0.05, y2: 0.53 },
{ x: 2002, y: 0.91, y1: 0.06, y2: 0.57 },
{ x: 2003, y: 1, y1: 0.09, y2: 0.61 },
{ x: 2004, y: 1.19, y1: 0.14, y2: 0.63 },
{ x: 2005, y: 1.47, y1: 0.20, y2: 0.64 },
{ x: 2006, y: 1.74, y1: 0.29, y2: 0.66 },
{ x: 2007, y: 1.98, y1: 0.46, y2: 0.76 },
{ x: 2008, y: 1.99, y1: 0.64, y2: 0.77 },
{ x: 2009, y: 1.70, y1: 0.75, y2: 0.55 }
];Troubleshooting
The following list describes common issues you may encounter when working with the 100% Stacked Bar series and how to resolve them.
Chart does not render a 100% stacked bar: Confirm the type property of each series is set to StackingBar100. If type is omitted or set to a different value (for example, StackingBar), the data is drawn as overlapping (non-normalized) segments. Also ensure StackingBarSeries is registered with Chart.Inject(...) before the chart is initialized, or import the module directly from @syncfusion/ej2-charts using ES module syntax.
Cylindrical facet does not appear: columnFacet accepts only Rectangle (the default) and Cylinder. Other values are ignored. Confirm the property is set on each series configuration object and that the chart is rendered with the StackingBar100 series type.
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.