How can I help you?
Stacked Bar Chart in EJ2 JavaScript 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.
var stackedData = [
{ 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 }
];
var chart = new ej.charts.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://cdn.syncfusion.com/ej2/33.1.44/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>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.
var stackedData = [
{ 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 }
];
var chart = new ej.charts.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://cdn.syncfusion.com/ej2/33.1.44/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>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.
var stackedData = [
{ 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 }
];
var chart = new ej.charts.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://cdn.syncfusion.com/ej2/33.1.44/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>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.
var stackedData = [
{ 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 }
];
var chart = new ej.charts.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://cdn.syncfusion.com/ej2/33.1.44/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<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>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>Opacity
The opacity property controls the transparency of the fill and affects how the series blends with background or overlapping series.
var stackedData = [
{ 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 }
];
var chart = new ej.charts.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://cdn.syncfusion.com/ej2/33.1.44/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>Border
Use the border property to configure the border width, color, and dasharray of the 100% stacked bar series.
var stackedData = [
{ 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 }
];
var chart = new ej.charts.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://cdn.syncfusion.com/ej2/33.1.44/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>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.
var cylindricalData = [
{ 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 }
];
var chart = new ej.charts.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://cdn.syncfusion.com/ej2/33.1.44/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>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.
var stackedData = [
{ 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 }
];
var chart = new ej.charts.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://cdn.syncfusion.com/ej2/33.1.44/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>Fill
Use the fill property to set the fill color for empty points.
var stackedData = [
{ 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 }
];
var chart = new ej.charts.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://cdn.syncfusion.com/ej2/33.1.44/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>Border
Use the border property to customize the border width and color for empty points.
var stackedData = [
{ 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 }
];
var chart = new ej.charts.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://cdn.syncfusion.com/ej2/33.1.44/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>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.
var stackedData = [
{ 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 }
];
var chart = new ej.charts.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: function (args) {
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://cdn.syncfusion.com/ej2/33.1.44/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>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.
var stackedData = [
{ 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 }
];
var chart = new ej.charts.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: function (args) {
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://cdn.syncfusion.com/ej2/33.1.44/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>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.
var stackedData = [
{ 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 }
];
var chart = new ej.charts.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: function (args) {
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://cdn.syncfusion.com/ej2/33.1.44/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>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.
var stackedData = [
{ 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 }
];
var chart = new ej.charts.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: function (args) {
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://cdn.syncfusion.com/ej2/33.1.44/dist/ej2.min.js" type="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="element"></div>
</div>
<script>
var ele = document.getElementById('container');
if (ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body>
</html>