How can I help you?
Stacked Bar Chart in EJ2 TypeScript Charts
3 Feb 202624 minutes to read
100% Stacked Bar
To render a 100% stacked bar 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
typeasStackingBar100in your chart configuration. This indicates that the data should be represented as a 100% stacked bar chart, with segments that show the percentage contribution of each part. -
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>
<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: 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>
<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: 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.
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>
<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: 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 }
];The fill property can be used to apply a gradient color to the 100% stacked bar 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, 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>
<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>
</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>
<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: 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 dasharray 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>
<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: 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. This property transforms the regular 100% stacked bars into cylindrical shapes, enhancing the visual representation of the data.
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>
<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: 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. Empty data points are ignored and not plotted on the chart.
Mode
Use the mode property to control handling of empty points. Available modes: Gap, Drop, Zero, 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>
<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: 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>
<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: 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>
<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: 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, giving your chart a more polished appearance. 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>
<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: 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>
<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: 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>
<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: 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>
<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: 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 }
];