Stacked bar chart in TypeScript 3D Chart control
18 Nov 201824 minutes to read
Stacked bar chart
To render a stacked bar series, use series type as StackingBar and inject StackingBarSeries3D module using Chart3D.Inject(StackingBarSeries3D) method.
import {Chart3D, Category3D, Legend3D, StackingBarSeries3D, Tooltip3D, Highlight3D, Chart3DLoadedEventArgs } from '@syncfusion/ej2-charts';
Chart3D.Inject(StackingBarSeries3D, Category3D, Legend3D, Tooltip3D, Highlight3D);
let chart: Chart3D = new Chart3D({
primaryXAxis: {
valueType: 'Category'
},
//Initializing Primary Y Axis
primaryYAxis:
{
interval: 20
},
//Initializing Chart Series
series: [
{
type: 'StackingBar',
dataSource: [
{ x: 'Sochi', y: 9 },
{ x: 'Rio', y: 46 },
{ x: 'Pyeongchang', y: 9 },
{ x: 'Tokyo', y: 39 },
{ x: 'Beijing', y: 8 },
],
name: 'America',
xName: 'x',
yName: 'y'
},
{
type: 'StackingBar',
dataSource: [
{ x: 'Sochi', y: 10 },
{ x: 'Rio', y: 4 },
{ x: 'Pyeongchang', y: 11 },
{ x: 'Tokyo', y: 7 },
{ x: 'Beijing', y: 4 },],
name: 'Canada',
xName: 'x',
yName: 'y'
},
{
type: 'StackingBar',
dataSource: [
{ x: 'Sochi', y: 4 },
{ x: 'Rio', y: 10 },
{ x: 'Pyeongchang', y: 5 },
{ x: 'Tokyo', y: 10 },
{ x: 'Beijing', y: 5 },],
name: 'France',
xName: 'x',
yName: 'y'
}
],
enableRotation: true,
rotation: 22,
depth: 100,
legendSettings: {
enableHighlight: 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>Stacking group
To group the stacked bar, the stackingGroup property can be used. The columns with same group name are stacked on top of each other.
import {Chart3D, Category3D, Legend3D, StackingBarSeries3D, Tooltip3D, Highlight3D, Chart3DLoadedEventArgs } from '@syncfusion/ej2-charts';
Chart3D.Inject(StackingBarSeries3D, Category3D, Legend3D, Tooltip3D, Highlight3D);
let chart: Chart3D = new Chart3D({
primaryXAxis: {
valueType: 'Category'
},
//Initializing Primary Y Axis
primaryYAxis:
{
interval: 20
},
//Initializing Chart Series
series: [
{
type: 'StackingBar',
dataSource: [
{ x: 'Sochi', y: 9 },
{ x: 'Rio', y: 46 },
{ x: 'Pyeongchang', y: 9 },
{ x: 'Tokyo', y: 39 },
{ x: 'Beijing', y: 8 },
],
stackingGroup: 'JohnAndAndrew',
name: 'America',
xName: 'x',
yName: 'y'
},
{
type: 'StackingBar',
dataSource: [
{ x: 'Sochi', y: 10 },
{ x: 'Rio', y: 4 },
{ x: 'Pyeongchang', y: 11 },
{ x: 'Tokyo', y: 7 },
{ x: 'Beijing', y: 4 },],
name: 'Canada',
stackingGroup: 'JohnAndAndrew',
xName: 'x',
yName: 'y'
},
{
type: 'StackingBar',
dataSource: [
{ x: 'Sochi', y: 4 },
{ x: 'Rio', y: 10 },
{ x: 'Pyeongchang', y: 5 },
{ x: 'Tokyo', y: 10 },
{ x: 'Beijing', y: 5 },],
name: 'France',
stackingGroup: 'ThomasAndMichael',
xName: 'x',
yName: 'y'
}
],
enableRotation: true,
rotation: 22,
depth: 100,
legendSettings: {
enableHighlight: 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>Cylindrical stacked bar chart
To render a cylindrical stacked bar chart, set the columnFacet property to Cylinder in the chart series.
import {Chart3D, Category3D, Legend3D, StackingBarSeries3D, Tooltip3D, Highlight3D, Chart3DLoadedEventArgs } from '@syncfusion/ej2-charts';
Chart3D.Inject(StackingBarSeries3D, Category3D, Legend3D, Tooltip3D, Highlight3D);
let chart: Chart3D = new Chart3D({
primaryXAxis: {
valueType: 'Category'
},
//Initializing Primary Y Axis
primaryYAxis:
{
interval: 20
},
//Initializing Chart Series
series: [
{
type: 'StackingBar',
dataSource: [
{ x: 'Sochi', y: 9 },
{ x: 'Rio', y: 46 },
{ x: 'Pyeongchang', y: 9 },
{ x: 'Tokyo', y: 39 },
{ x: 'Beijing', y: 8 },
],
columnFacet: "Cylinder",
name: 'America',
xName: 'x',
yName: 'y'
},
{
type: 'StackingBar',
dataSource: [
{ x: 'Sochi', y: 10 },
{ x: 'Rio', y: 4 },
{ x: 'Pyeongchang', y: 11 },
{ x: 'Tokyo', y: 7 },
{ x: 'Beijing', y: 4 },],
name: 'Canada',
columnFacet: "Cylinder",
xName: 'x',
yName: 'y'
},
{
type: 'StackingBar',
dataSource: [
{ x: 'Sochi', y: 4 },
{ x: 'Rio', y: 10 },
{ x: 'Pyeongchang', y: 5 },
{ x: 'Tokyo', y: 10 },
{ x: 'Beijing', y: 5 },],
name: 'France',
columnFacet: "Cylinder",
xName: 'x',
yName: 'y'
}
],
enableRotation: true,
rotation: 22,
depth: 100,
legendSettings: {
enableHighlight: 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>Series customization
The following properties can be used to customize the stacked bar series.
import {Chart3D, Category3D, Legend3D, StackingBarSeries3D, Tooltip3D, Highlight3D, Chart3DLoadedEventArgs } from '@syncfusion/ej2-charts';
Chart3D.Inject(StackingBarSeries3D, Category3D, Legend3D, Tooltip3D, Highlight3D);
let chart: Chart3D = new Chart3D({
primaryXAxis: {
valueType: 'Category'
},
primaryYAxis:
{
interval: 20
},
series: [
{
type: 'StackingBar',
dataSource: [
{ x: 'Sochi', y: 9 },
{ x: 'Rio', y: 46 },
{ x: 'Pyeongchang', y: 9 },
{ x: 'Tokyo', y: 39 },
{ x: 'Beijing', y: 8 },
],
fill: "red",
name: 'America',
xName: 'x',
yName: 'y'
},
{
type: 'StackingBar',
dataSource: [
{ x: 'Sochi', y: 10 },
{ x: 'Rio', y: 4 },
{ x: 'Pyeongchang', y: 11 },
{ x: 'Tokyo', y: 7 },
{ x: 'Beijing', y: 4 },],
name: 'Canada',
fill: "green",
xName: 'x',
yName: 'y'
},
{
type: 'StackingBar',
dataSource: [
{ x: 'Sochi', y: 4 },
{ x: 'Rio', y: 10 },
{ x: 'Pyeongchang', y: 5 },
{ x: 'Tokyo', y: 10 },
{ x: 'Beijing', y: 5 },],
name: 'France',
fill: "yellow",
xName: 'x',
yName: 'y'
}
],
enableRotation: true,
rotation: 22,
depth: 100,
legendSettings: {
enableHighlight: 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>