Stack column Chart in EJ2 TypeScript control
20 Sep 202424 minutes to read
Stacked column
To render a stacked column series in your chart, you need to follow a few steps to configure it correctly. Here’s a concise guide on how to do this:
-
Set the series type: Define the series
type
asStackingColumn
in your chart configuration. This indicates that the data should be represented as a stacked column chart, where each column consists of multiple segments stacked on top of each other. -
Inject the StackingColumnSeries module: Use the
Chart.Inject(StackingColumnSeries)
method to inject theStackingColumnSeries
module into your chart. This step is essential, as it ensures that the necessary functionalities for rendering stacked column series are available in your chart.
import { Chart, StackingColumnSeries, Category, Legend } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingColumnSeries, Category, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Years',
interval: 1,
valueType: 'Category'
},
primaryYAxis:
{
title: 'Sales in Billions',
minimum: 0,
maximum: 700,
interval: 100,
labelFormat: '{value}B'
},
series: [
{
dataSource: stackedData, xName: 'x', yName: 'y',
//Series type as stacked column
type: 'StackingColumn', name: 'UK'
},
{
dataSource: stackedData, xName: 'x', yName: 'y1',
type: 'StackingColumn', name: 'Germany'
},
{
dataSource: stackedData, xName: 'x', yName: 'y2',
type: 'StackingColumn', name: 'France'
},
{
dataSource: stackedData, xName: 'x', yName: 'y3',
type: 'StackingColumn', name: 'Italy'
}
],
title: 'Mobile Game Market by Country'
}, '#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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
export let stackedData: Object[] = [
{ x: '2014', y: 111.1, y1: 76.9, y2: 66.1, y3: 34.1 },
{ x: '2015', y: 127.3, y1: 99.5, y2: 79.3, y3: 38.2 },
{ x: '2016', y: 143.4, y1: 121.7, y2: 91.3, y3: 44.0 },
{ x: '2017', y: 159.9, y1: 142.5, y2: 102.4, y3: 51.6 },
{ x: '2018', y: 175.4, y1: 166.7, y2: 112.9, y3: 61.9 },
{ x: '2019', y: 189.0, y1: 182.9, y2: 122.4, y3: 71.5 },
{ x: '2020', y: 202.7, y1: 197.3, y2: 120.9, y3: 82.0 }
];
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, StackingColumnSeries, Category, Legend } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingColumnSeries, Category, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Years',
interval: 1,
valueType: 'Category'
},
primaryYAxis:
{
title: 'Sales in Billions',
minimum: 0,
maximum: 700,
interval: 100,
labelFormat: '{value}B'
},
series: [
{
dataSource: stackedData, xName: 'x', yName: 'y',
//Series type as stacked column
type: 'StackingColumn', name: 'UK'
},
{
dataSource: stackedData, xName: 'x', yName: 'y1',
type: 'StackingColumn', name: 'Germany'
},
{
dataSource: stackedData, xName: 'x', yName: 'y2',
type: 'StackingColumn', name: 'France'
},
{
dataSource: stackedData, xName: 'x', yName: 'y3',
type: 'StackingColumn', name: 'Italy'
}
],
title: 'Mobile Game Market by Country'
}, '#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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
export let stackedData: Object[] = [
{ x: '2014', y: 111.1, y1: 76.9, y2: 66.1, y3: 34.1 },
{ x: '2015', y: 127.3, y1: 99.5, y2: 79.3, y3: 38.2 },
{ x: '2016', y: 143.4, y1: 121.7, y2: 91.3, y3: 44.0 },
{ x: '2017', y: 159.9, y1: 142.5, y2: 102.4, y3: 51.6 },
{ x: '2018', y: 175.4, y1: 166.7, y2: 112.9, y3: 61.9 },
{ x: '2019', y: 189.0, y1: 182.9, y2: 122.4, y3: 71.5 },
{ x: '2020', y: 202.7, y1: 197.3, y2: 120.9, y3: 82.0 }
];
Series customization
The following properties can be used to customize the stacked column
series.
Fill
The fill property determines the color applied to the series.
import { Chart, StackingColumnSeries, Category, Legend } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingColumnSeries, Category, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Years',
interval: 1,
valueType: 'Category'
},
primaryYAxis:
{
title: 'Sales in Billions',
minimum: 0,
maximum: 700,
interval: 100,
labelFormat: '{value}B'
},
series: [
{
dataSource: stackedData, xName: 'x', yName: 'y',
//Series type as stacked column
type: 'StackingColumn', name: 'UK', fill: '#2F4F4F'
},
{
dataSource: stackedData, xName: 'x', yName: 'y1',
type: 'StackingColumn', name: 'Germany', fill: '#556B2F'
},
{
dataSource: stackedData, xName: 'x', yName: 'y2',
type: 'StackingColumn', name: 'France', fill: '#8B0000'
},
{
dataSource: stackedData, xName: 'x', yName: 'y3',
type: 'StackingColumn', name: 'Italy', fill: '#00008B'
}
],
title: 'Mobile Game Market by Country'
}, '#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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
export let stackedData: Object[] = [
{ x: '2014', y: 111.1, y1: 76.9, y2: 66.1, y3: 34.1 },
{ x: '2015', y: 127.3, y1: 99.5, y2: 79.3, y3: 38.2 },
{ x: '2016', y: 143.4, y1: 121.7, y2: 91.3, y3: 44.0 },
{ x: '2017', y: 159.9, y1: 142.5, y2: 102.4, y3: 51.6 },
{ x: '2018', y: 175.4, y1: 166.7, y2: 112.9, y3: 61.9 },
{ x: '2019', y: 189.0, y1: 182.9, y2: 122.4, y3: 71.5 },
{ x: '2020', y: 202.7, y1: 197.3, y2: 120.9, y3: 82.0 }
];
The fill property can be used to apply a gradient color to the stacked column series. By configuring this property with gradient values, you can create a visually appealing effect in which the color transitions smoothly from one shade to another.
import { Chart, StackingColumnSeries, Category, Legend } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingColumnSeries, Category, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Years',
interval: 1,
valueType: 'Category'
},
primaryYAxis:
{
title: 'Sales in Billions',
minimum: 0,
maximum: 700,
interval: 100,
labelFormat: '{value}B'
},
series: [
{
dataSource: stackedData, xName: 'x', yName: 'y',
//Series type as stacked column
type: 'StackingColumn', name: 'UK', fill: 'url(#gradient1)'
},
{
dataSource: stackedData, xName: 'x', yName: 'y1',
type: 'StackingColumn', name: 'Germany', fill: 'url(#gradient2)'
},
{
dataSource: stackedData, xName: 'x', yName: 'y2',
type: 'StackingColumn', name: 'France', fill: 'url(#gradient3)'
},
{
dataSource: stackedData, xName: 'x', yName: 'y3',
type: 'StackingColumn', name: 'Italy', fill: 'url(#gradient4)'
}
],
title: 'Mobile Game Market by Country'
}, '#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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></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 stackedData: Object[] = [
{ x: '2014', y: 111.1, y1: 76.9, y2: 66.1, y3: 34.1 },
{ x: '2015', y: 127.3, y1: 99.5, y2: 79.3, y3: 38.2 },
{ x: '2016', y: 143.4, y1: 121.7, y2: 91.3, y3: 44.0 },
{ x: '2017', y: 159.9, y1: 142.5, y2: 102.4, y3: 51.6 },
{ x: '2018', y: 175.4, y1: 166.7, y2: 112.9, y3: 61.9 },
{ x: '2019', y: 189.0, y1: 182.9, y2: 122.4, y3: 71.5 },
{ x: '2020', y: 202.7, y1: 197.3, y2: 120.9, y3: 82.0 }
];
Opacity
The opacity property specifies the transparency level of the fill. Adjusting this property allows you to control how opaque or transparent the fill color of the series appears.
import { Chart, StackingColumnSeries, Category, Legend } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingColumnSeries, Category, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Years',
interval: 1,
valueType: 'Category'
},
primaryYAxis:
{
title: 'Sales in Billions',
minimum: 0,
maximum: 700,
interval: 100,
labelFormat: '{value}B'
},
series: [
{
dataSource: stackedData, xName: 'x', yName: 'y',
//Series type as stacked column
type: 'StackingColumn', name: 'UK', opacity: 0.7
},
{
dataSource: stackedData, xName: 'x', yName: 'y1',
type: 'StackingColumn', name: 'Germany', opacity: 0.7
},
{
dataSource: stackedData, xName: 'x', yName: 'y2',
type: 'StackingColumn', name: 'France', opacity: 0.7
},
{
dataSource: stackedData, xName: 'x', yName: 'y3',
type: 'StackingColumn', name: 'Italy', opacity: 0.7
}
],
title: 'Mobile Game Market by Country'
}, '#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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
export let stackedData: Object[] = [
{ x: '2014', y: 111.1, y1: 76.9, y2: 66.1, y3: 34.1 },
{ x: '2015', y: 127.3, y1: 99.5, y2: 79.3, y3: 38.2 },
{ x: '2016', y: 143.4, y1: 121.7, y2: 91.3, y3: 44.0 },
{ x: '2017', y: 159.9, y1: 142.5, y2: 102.4, y3: 51.6 },
{ x: '2018', y: 175.4, y1: 166.7, y2: 112.9, y3: 61.9 },
{ x: '2019', y: 189.0, y1: 182.9, y2: 122.4, y3: 71.5 },
{ x: '2020', y: 202.7, y1: 197.3, y2: 120.9, y3: 82.0 }
];
Dash array
The dashArray property determines the pattern of dashes and gaps in the series.
import { Chart, StackingColumnSeries, Category, Legend } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingColumnSeries, Category, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Years',
interval: 1,
valueType: 'Category'
},
primaryYAxis:
{
title: 'Sales in Billions',
minimum: 0,
maximum: 700,
interval: 100,
labelFormat: '{value}B'
},
series: [
{
dataSource: stackedData, xName: 'x', yName: 'y',
//Series type as stacked column
type: 'StackingColumn', name: 'UK', dashArray: '5,5',
border: { width: 2, color: '#ff4251'}
},
{
dataSource: stackedData, xName: 'x', yName: 'y1',
type: 'StackingColumn', name: 'Germany', dashArray: '5,5',
border: { width: 2, color: '#4C4C4C'}
},
{
dataSource: stackedData, xName: 'x', yName: 'y2',
type: 'StackingColumn', name: 'France', dashArray: '5,5',
border: { width: 2, color: '#794F1B'}
},
{
dataSource: stackedData, xName: 'x', yName: 'y3',
type: 'StackingColumn', name: 'Italy', dashArray: '5,5',
border: { width: 2, color: '#1a9a6f'}
}
],
title: 'Mobile Game Market by Country'
}, '#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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
export let stackedData: Object[] = [
{ x: '2014', y: 111.1, y1: 76.9, y2: 66.1, y3: 34.1 },
{ x: '2015', y: 127.3, y1: 99.5, y2: 79.3, y3: 38.2 },
{ x: '2016', y: 143.4, y1: 121.7, y2: 91.3, y3: 44.0 },
{ x: '2017', y: 159.9, y1: 142.5, y2: 102.4, y3: 51.6 },
{ x: '2018', y: 175.4, y1: 166.7, y2: 112.9, y3: 61.9 },
{ x: '2019', y: 189.0, y1: 182.9, y2: 122.4, y3: 71.5 },
{ x: '2020', y: 202.7, y1: 197.3, y2: 120.9, y3: 82.0 }
];
Border
Use the border property to customize the width and color of the series border.
import { Chart, StackingColumnSeries, Category, Legend } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingColumnSeries, Category, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Years',
interval: 1,
valueType: 'Category'
},
primaryYAxis:
{
title: 'Sales in Billions',
minimum: 0,
maximum: 700,
interval: 100,
labelFormat: '{value}B'
},
series: [
{
dataSource: stackedData, xName: 'x', yName: 'y',
//Series type as stacked column
type: 'StackingColumn', name: 'UK',
border: { width: 2, color: '#ff4251'}
},
{
dataSource: stackedData, xName: 'x', yName: 'y1',
type: 'StackingColumn', name: 'Germany',
border: { width: 2, color: '#66BDB7'}
},
{
dataSource: stackedData, xName: 'x', yName: 'y2',
type: 'StackingColumn', name: 'France',
border: { width: 2, color: '#794F1B'}
},
{
dataSource: stackedData, xName: 'x', yName: 'y3',
type: 'StackingColumn', name: 'Italy',
border: { width: 2, color: '#1a9a6f'}
}
],
title: 'Mobile Game Market by Country'
}, '#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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
export let stackedData: Object[] = [
{ x: '2014', y: 111.1, y1: 76.9, y2: 66.1, y3: 34.1 },
{ x: '2015', y: 127.3, y1: 99.5, y2: 79.3, y3: 38.2 },
{ x: '2016', y: 143.4, y1: 121.7, y2: 91.3, y3: 44.0 },
{ x: '2017', y: 159.9, y1: 142.5, y2: 102.4, y3: 51.6 },
{ x: '2018', y: 175.4, y1: 166.7, y2: 112.9, y3: 61.9 },
{ x: '2019', y: 189.0, y1: 182.9, y2: 122.4, y3: 71.5 },
{ x: '2020', y: 202.7, y1: 197.3, y2: 120.9, y3: 82.0 }
];
Stacking group
Use the stackingGroup
property to group stacked columns and 100% stacked columns. Columns with the same group name are stacked on top of each other.
import { Chart, StackingColumnSeries, Category, Legend } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingColumnSeries, Category, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Years',
interval: 1,
valueType: 'Category'
},
primaryYAxis:
{
title: 'Sales in Billions',
minimum: 0,
maximum: 400,
interval: 100,
labelFormat: '{value}B'
},
series: [
{
dataSource: stackedData, xName: 'x', yName: 'y',
type: 'StackingColumn', name: 'UK',
//Stacking group for stacked column series
stackingGroup: 'UKAndGermany'
},
{
dataSource: stackedData, xName: 'x', yName: 'y1',
type: 'StackingColumn', name: 'Germany',
stackingGroup: 'UKAndGermany'
},
{
dataSource: stackedData, xName: 'x', yName: 'y2',
type: 'StackingColumn', name: 'France',
stackingGroup: 'FranceAndItaly'
},
{
dataSource: stackedData, xName: 'x', yName: 'y3',
type: 'StackingColumn', name: 'Italy',
stackingGroup: 'FranceAndItaly'
}
],
title: 'Mobile Game Market by Country'
}, '#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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
export let stackedData: Object[] = [
{ x: '2014', y: 111.1, y1: 76.9, y2: 66.1, y3: 34.1 },
{ x: '2015', y: 127.3, y1: 99.5, y2: 79.3, y3: 38.2 },
{ x: '2016', y: 143.4, y1: 121.7, y2: 91.3, y3: 44.0 },
{ x: '2017', y: 159.9, y1: 142.5, y2: 102.4, y3: 51.6 },
{ x: '2018', y: 175.4, y1: 166.7, y2: 112.9, y3: 61.9 },
{ x: '2019', y: 189.0, y1: 182.9, y2: 122.4, y3: 71.5 },
{ x: '2020', y: 202.7, y1: 197.3, y2: 120.9, y3: 82.0 }
];
Cylindrical stacked column chart
To render a cylindrical stacked column chart, set the columnFacet
property to Cylinder
in the chart series. This property transforms the regular stacked columns into cylindrical shapes, enhancing the visual representation of the data.
import { Chart, StackingColumnSeries, Category, Legend } from '@syncfusion/ej2-charts';
import { cylindricalData } from './datasource.ts';
Chart.Inject(StackingColumnSeries, Category, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Years',
interval: 1,
valueType: 'Category'
},
primaryYAxis:
{
title: 'Sales in Billions',
minimum: 0,
maximum: 700,
interval: 100,
labelFormat: '{value}B'
},
//Series type as stacked column with cylinder shape
series: [
{
dataSource: cylindricalData, xName: 'x', yName: 'y',
type: 'StackingColumn', columnFacet: 'Cylinder', name: 'UK'
},
{
dataSource: cylindricalData, xName: 'x', yName: 'y1',
type: 'StackingColumn', columnFacet: 'Cylinder', name: 'Germany'
},
{
dataSource: cylindricalData, xName: 'x', yName: 'y2',
type: 'StackingColumn', columnFacet: 'Cylinder', name: 'France'
},
{
dataSource: cylindricalData, xName: 'x', yName: 'y3',
type: 'StackingColumn', columnFacet: 'Cylinder', name: 'Italy'
}
],
title: 'Mobile Game Market by Country'
}, '#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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
export let cylindricalData: Object[] = [
{ x: '2014', y: 111.1, y1: 76.9, y2: 66.1, y3: 34.1 },
{ x: '2015', y: 127.3, y1: 99.5, y2: 79.3, y3: 38.2 },
{ x: '2016', y: 143.4, y1: 121.7, y2: 91.3, y3: 44.0 },
{ x: '2017', y: 159.9, y1: 142.5, y2: 102.4, y3: 51.6 },
{ x: '2018', y: 175.4, y1: 166.7, y2: 112.9, y3: 61.9 },
{ x: '2019', y: 189.0, y1: 182.9, y2: 122.4, y3: 71.5 },
{ x: '2020', y: 202.7, y1: 197.3, y2: 120.9, y3: 82.0 }
];
Empty points
Data points with null
or undefined
values are considered empty. Empty data points are ignored and not plotted on the chart.
Mode
Use the mode
property to define how empty or missing data points are handled in the series. The default mode for empty points is Gap
.
import { Chart, StackingColumnSeries, Category, Legend } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingColumnSeries, Category, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Years',
interval: 1,
valueType: 'Category'
},
primaryYAxis:
{
title: 'Sales in Billions',
minimum: 0,
maximum: 700,
interval: 100,
labelFormat: '{value}B'
},
series: [
{
dataSource: stackedData, xName: 'x', yName: 'y',
//Series type as stacked column
type: 'StackingColumn', name: 'UK',
emptyPointSettings: {
mode: 'Zero'
}
},
{
dataSource: stackedData, xName: 'x', yName: 'y1',
type: 'StackingColumn', name: 'Germany'
},
{
dataSource: stackedData, xName: 'x', yName: 'y2',
type: 'StackingColumn', name: 'France',
emptyPointSettings: {
mode: 'Average'
}
},
{
dataSource: stackedData, xName: 'x', yName: 'y3',
type: 'StackingColumn', name: 'Italy'
}
],
title: 'Mobile Game Market by Country'
}, '#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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
export let stackedData: Object[] = [
{ x: '2014', y: 111.1, y1: 76.9, y2: 66.1, y3: 34.1 },
{ x: '2015', y: 127.3, y1: 99.5, y2: 79.3, y3: 38.2 },
{ x: '2016', y: null, y1: 121.7, y2: 91.3, y3: 44.0 },
{ x: '2017', y: 159.9, y1: 142.5, y2: 102.4, y3: 51.6 },
{ x: '2018', y: 175.4, y1: 166.7, y2: 112.9, y3: 61.9 },
{ x: '2019', y: 189.0, y1: 182.9, y2: null, y3: 71.5 },
{ x: '2020', y: 202.7, y1: 197.3, y2: 120.9, y3: 82.0 }
];
Fill
Use the fill
property to customize the fill color of empty points in the series.
import { Chart, StackingColumnSeries, Category, Legend } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingColumnSeries, Category, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Years',
interval: 1,
valueType: 'Category'
},
primaryYAxis:
{
title: 'Sales in Billions',
minimum: 0,
maximum: 700,
interval: 100,
labelFormat: '{value}B'
},
series: [
{
dataSource: stackedData, xName: 'x', yName: 'y',
//Series type as stacked column
type: 'StackingColumn', name: 'UK',
emptyPointSettings: {
mode: 'Zero'
}
},
{
dataSource: stackedData, xName: 'x', yName: 'y1',
type: 'StackingColumn', name: 'Germany'
},
{
dataSource: stackedData, xName: 'x', yName: 'y2',
type: 'StackingColumn', name: 'France',
emptyPointSettings: {
mode: 'Average',
fill: 'red'
}
},
{
dataSource: stackedData, xName: 'x', yName: 'y3',
type: 'StackingColumn', name: 'Italy'
}
],
title: 'Mobile Game Market by Country'
}, '#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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
export let stackedData: Object[] = [
{ x: '2014', y: 111.1, y1: 76.9, y2: 66.1, y3: 34.1 },
{ x: '2015', y: 127.3, y1: 99.5, y2: 79.3, y3: 38.2 },
{ x: '2016', y: null, y1: 121.7, y2: 91.3, y3: 44.0 },
{ x: '2017', y: 159.9, y1: 142.5, y2: 102.4, y3: 51.6 },
{ x: '2018', y: 175.4, y1: 166.7, y2: 112.9, y3: 61.9 },
{ x: '2019', y: 189.0, y1: 182.9, y2: null, y3: 71.5 },
{ x: '2020', y: 202.7, y1: 197.3, y2: 120.9, y3: 82.0 }
];
Border
Use the border
property to customize the width and color of the border for empty points.
import { Chart, StackingColumnSeries, Category, Legend } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingColumnSeries, Category, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Years',
interval: 1,
valueType: 'Category'
},
primaryYAxis:
{
title: 'Sales in Billions',
minimum: 0,
maximum: 700,
interval: 100,
labelFormat: '{value}B'
},
series: [
{
dataSource: stackedData, xName: 'x', yName: 'y',
//Series type as stacked column
type: 'StackingColumn', name: 'UK',
emptyPointSettings: {
mode: 'Zero'
}
},
{
dataSource: stackedData, xName: 'x', yName: 'y1',
type: 'StackingColumn', name: 'Germany'
},
{
dataSource: stackedData, xName: 'x', yName: 'y2',
type: 'StackingColumn', name: 'France',
emptyPointSettings: {
mode: 'Average',
fill: 'red',
border: { width: 2, color: 'green' }
}
},
{
dataSource: stackedData, xName: 'x', yName: 'y3',
type: 'StackingColumn', name: 'Italy'
}
],
title: 'Mobile Game Market by Country'
}, '#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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
export let stackedData: Object[] = [
{ x: '2014', y: 111.1, y1: 76.9, y2: 66.1, y3: 34.1 },
{ x: '2015', y: 127.3, y1: 99.5, y2: 79.3, y3: 38.2 },
{ x: '2016', y: null, y1: 121.7, y2: 91.3, y3: 44.0 },
{ x: '2017', y: 159.9, y1: 142.5, y2: 102.4, y3: 51.6 },
{ x: '2018', y: 175.4, y1: 166.7, y2: 112.9, y3: 61.9 },
{ x: '2019', y: 189.0, y1: 182.9, y2: null, y3: 71.5 },
{ x: '2020', y: 202.7, y1: 197.3, y2: 120.9, y3: 82.0 }
];
Events
Series render
The seriesRender
event allows you to customize series properties, such as data, fill, and name, before they are rendered on the chart.
import { Chart, StackingColumnSeries, Category, Legend, ISeriesRenderEventArgs } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingColumnSeries, Category, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Years',
interval: 1,
valueType: 'Category'
},
primaryYAxis:
{
title: 'Sales in Billions',
minimum: 0,
maximum: 700,
interval: 100,
labelFormat: '{value}B'
},
series: [
{
dataSource: stackedData, xName: 'x', yName: 'y',
//Series type as stacked column
type: 'StackingColumn', name: 'UK'
},
{
dataSource: stackedData, xName: 'x', yName: 'y1',
type: 'StackingColumn', name: 'Germany'
},
{
dataSource: stackedData, xName: 'x', yName: 'y2',
type: 'StackingColumn', name: 'France'
},
{
dataSource: stackedData, xName: 'x', yName: 'y3',
type: 'StackingColumn', name: 'Italy'
}
],
title: 'Mobile Game Market by Country',
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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
export let stackedData: Object[] = [
{ x: '2014', y: 111.1, y1: 76.9, y2: 66.1, y3: 34.1 },
{ x: '2015', y: 127.3, y1: 99.5, y2: 79.3, y3: 38.2 },
{ x: '2016', y: 143.4, y1: 121.7, y2: 91.3, y3: 44.0 },
{ x: '2017', y: 159.9, y1: 142.5, y2: 102.4, y3: 51.6 },
{ x: '2018', y: 175.4, y1: 166.7, y2: 112.9, y3: 61.9 },
{ x: '2019', y: 189.0, y1: 182.9, y2: 122.4, y3: 71.5 },
{ x: '2020', y: 202.7, y1: 197.3, y2: 120.9, y3: 82.0 }
];
Point render
The pointRender
event allows you to customize each data point before it is rendered on the chart.
import { Chart, StackingColumnSeries, Category, Legend, IPointRenderEventArgs } from '@syncfusion/ej2-charts';
import { stackedData } from './datasource.ts';
Chart.Inject(StackingColumnSeries, Category, Legend);
let chart: Chart = new Chart({
primaryXAxis: {
title: 'Years',
interval: 1,
valueType: 'Category'
},
primaryYAxis:
{
title: 'Sales in Billions',
minimum: 0,
maximum: 700,
interval: 100,
labelFormat: '{value}B'
},
series: [
{
dataSource: stackedData, xName: 'x', yName: 'y',
//Series type as stacked column
type: 'StackingColumn', name: 'UK'
},
{
dataSource: stackedData, xName: 'x', yName: 'y1',
type: 'StackingColumn', name: 'Germany'
},
{
dataSource: stackedData, xName: 'x', yName: 'y2',
type: 'StackingColumn', name: 'France'
},
{
dataSource: stackedData, xName: 'x', yName: 'y3',
type: 'StackingColumn', name: 'Italy'
}
],
title: 'Mobile Game Market by Country',
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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
export let stackedData: Object[] = [
{ x: '2014', y: 111.1, y1: 76.9, y2: 66.1, y3: 34.1 },
{ x: '2015', y: 127.3, y1: 99.5, y2: 79.3, y3: 38.2 },
{ x: '2016', y: 143.4, y1: 121.7, y2: 91.3, y3: 44.0 },
{ x: '2017', y: 159.9, y1: 142.5, y2: 102.4, y3: 51.6 },
{ x: '2018', y: 175.4, y1: 166.7, y2: 112.9, y3: 61.9 },
{ x: '2019', y: 189.0, y1: 182.9, y2: 122.4, y3: 71.5 },
{ x: '2020', y: 202.7, y1: 197.3, y2: 120.9, y3: 82.0 }
];