To render a 100% stacked bar series, use series type
as
StackingBar100
and inject StackingBarSeries
module using Chart.Inject(StackingBarSeries)
method.
var chartData = [
{ x: 'Jan', y: 6, y1: 6, y2: -1 }, { x: 'Feb', y: 8 , y1: 8, y2: -1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: -2 }, { x: 'Apr', y: 15, y1: 16, y2: -2.5 },
{ x: 'May', y: 20, y1: 21, y2: -3 }, { x: 'Jun', y: 24, y1: 25, y2: -3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: -4 }, { x: 'Aug', y: 32, y1: 31, y2: -4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: -5 }, { x: 'Oct', y: 35, y1: 34, y2: -5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: -6 }, { x: 'Dec', y: 42, y1: 42, y2: -6.5 }
];
var chart = new ej.charts.Chart({
primaryXAxis: {
valueType: 'Category',
title: 'Months'
},
primaryYAxis:
{
title: 'Percentage (%)',
minimum: -20,
maximum: 100,
labelFormat: '{value}%',
edgeLabelPlacement: 'Shift'
},
series: [
{
//Series type as 100% stacked bar
type: 'StackingBar100',
name: 'Apple',
dataSource: chartData, xName: 'x', yName: 'y'
}, {
type: 'StackingBar100', name: 'Orange',
dataSource: chartData, xName: 'x', yName: 'y1'
}, {
type: 'StackingBar100', name: 'Wastage',
dataSource: chartData, xName: 'x', yName: 'y2'
}
],
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/21.2.3/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 following properties can be used to customize the 100% stacked column
series.
fill
– Specifies the color of the series.opacity
– Specifies the opacity of fill
.dashArray
– Specifies the dashes of series.border
– Specifies the color
and width
of series border.var chartData = [
{ x: 'Jan', y: 6, y1: 6, y2: 1 },
{ x: 'Feb', y: 8, y1: 8, y2: 1.5 },
{ x: 'Mar', y: 12, y1: 11, y2: 2 },
{ x: 'Apr', y: 15, y1: 16, y2: 2.5 },
{ x: 'May', y: 20, y1: 21, y2: 3 },
{ x: 'Jun', y: 24, y1: 25, y2: 3.5 },
{ x: 'Jul', y: 28, y1: 27, y2: 4 },
{ x: 'Aug', y: 32, y1: 31, y2: 4.5 },
{ x: 'Sep', y: 33, y1: 34, y2: 5 },
{ x: 'Oct', y: 35, y1: 34, y2: 5.5 },
{ x: 'Nov', y: 40, y1: 41, y2: 6 },
{ x: 'Dec', y: 42, y1: 42, y2: 6.5 },
];
var chart = new ej.charts.Chart(
{
primaryXAxis: {
valueType: 'Category',
title: 'Months',
},
primaryYAxis: {
title: 'Percentage (%)',
labelFormat: '{value}%',
edgeLabelPlacement: 'Shift',
},
series: [
{
//Series type as 100% stacked bar
type: 'StackingBar100',
name: 'Apple',
dataSource: chartData,
xName: 'x', dashArray: '2.5',
yName: 'y',border: { width: 1.5, color: 'red'},
},
{
type: 'StackingBar100',
name: 'Orange',
dataSource: chartData,
xName: 'x', dashArray: '2.5',
yName: 'y1',border: { width: 1.5, color: 'red'},
},
{
type: 'StackingBar100',
name: 'Wastage',
dataSource: chartData,
xName: 'x', dashArray: '2.5',
yName: 'y2',border: { width: 1.5, color: '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/21.2.3/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>