To render a stacked bar series, use series type
as StackingBar
and inject StackingBarSeries
module
using Chart.Inject(StackingBarSeries)
method.
import { Chart, StackingBarSeries, Category } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingBarSeries, Category);
let chart: Chart = new Chart({
series: [
{
//Series type as stacked bar
type: 'StackingBar',
dataSource: stackedData, xName: 'x', yName: 'y'
}, {
type: 'StackingBar',
dataSource: stackedData, xName: 'x', yName: 'y1'
}, {
type: 'StackingBar',
dataSource: stackedData, xName: 'x', yName: 'y2'
}
],
}, '#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>
You can use the stackingGroup
property to group the stacked bar and 100% stacked bar.
Columns with same group name are stacked on top of each other.
import { Chart, StackingBarSeries } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingBarSeries);
let chart: Chart = new Chart({
series: [
{
type: 'StackingBar',
//Stacking group for stacked bar
stackingGroup: 'JohnAndAndrew',
dataSource: stackedData, xName: 'x', yName: 'y'
}, {
type: 'StackingBar', name: 'Andrew', stackingGroup: 'JohnAndAndrew',
dataSource: stackedData, xName: 'x', yName: 'y1'
}, {
type: 'StackingBar', name: 'Thomas', stackingGroup: 'ThomasAndMichael',
dataSource: stackedData, xName: 'x', yName: 'y2'
}
],
}, '#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>
The following properties can be used to customize the stacked bar
series.
fill
– Specifies the color of the series.opacity
– Specifies the opacity of fill
.dashArray
– Specifies the dashes of series.border
– Specifies the color
and width
of series border.import { Chart, StackingBarSeries } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingBarSeries);
let chart: Chart = new Chart({
series: [
{
type: 'StackingBar', name: 'John',
//Stacking group for stacked bar
stackingGroup: 'JohnAndAndrew', dashArray: '2.2',
dataSource: stackedData, xName: 'x', yName: 'y', border: { width: 2, color: 'red' }
}, {
type: 'StackingBar', name: 'Andrew', stackingGroup: 'JohnAndAndrew', dashArray: '2.2',
dataSource: stackedData, xName: 'x', yName: 'y1', border: { width: 2, color: 'grey' }
}, {
type: 'StackingBar', name: 'Thomas', stackingGroup: 'ThomasAndMichael', dashArray: '2.2',
dataSource: stackedData, xName: 'x', yName: 'y2', border: { width: 2, color: 'lime' }
}
],
}, '#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>