Stacked area Chart in EJ2 JavaScript control
28 Sep 202314 minutes to read
100% Stacked Area
To render a 100% stacked area series, use series type
as StackingArea100
and inject StackingAreaSeries
module using Chart.Inject(StackingAreaSeries)
method.
var chartData = [
{ x: new Date(2006, 0, 1), y: 34, y1: 51, y2: 14, y3: 37 },
{ x: new Date(2007, 0, 1), y: 20, y1: 26, y2: 34, y3: 15 },
{ x: new Date(2008, 0, 1), y: 40, y1: 37, y2: 73, y3: 53 },
{ x: new Date(2009, 0, 1), y: 51, y1: 51, y2: 51, y3: 51 },
{ x: new Date(2010, 0, 1), y: 26, y1: 26, y2: 26, y3: 26 },
{ x: new Date(2011, 0, 1), y: 37, y1: 37, y2: 37, y3: 37 },
{ x: new Date(2012, 0, 1), y: 54, y1: 43, y2: 12, y3: 54 },
{ x: new Date(2013, 0, 1), y: 44, y1: 23, y2: 16, y3: 44 },
{ x: new Date(2014, 0, 1), y: 48, y1: 55, y2: 34, y3: 23 }
];
var chart = new ej.charts.Chart({
primaryXAxis: {
title: 'Years',
valueType: 'DateTime',
intervalType: 'Years',
labelFormat: 'y',
edgeLabelPlacement: 'Shift'
},
primaryYAxis:
{
title: 'Temperature (%)',
labelFormat: '{value}%',
rangePadding: 'None'
},
series: [
{
dataSource: chartData, xName: 'x', yName: 'y',
//Series type as 100% stacked area series
type: 'StackingArea100',
name: 'USA',
}, {
dataSource: chartData, xName: 'x', yName: 'y1',
type: 'StackingArea100', name: 'UK',
}, {
dataSource: chartData, xName: 'x', yName: 'y2',
type: 'StackingArea100', name: 'Canada',
}, {
dataSource: chartData, xName: 'x', yName: 'y3',
type: 'StackingArea100', name: 'China',
}
],
title: 'Annual Temperature 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/23.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.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 area
series.
- fill – Specifies the color of the area series.
- opacity – Specifies the opacity of fill.
- dashArray – Specifies the dashes of series.
var chartData = [
{ x: new Date(2006, 0, 1), y: 34, y1: 51, y2: 14, y3: 37 },
{ x: new Date(2007, 0, 1), y: 20, y1: 26, y2: 34, y3: 15 },
{ x: new Date(2008, 0, 1), y: 40, y1: 37, y2: 73, y3: 53 },
{ x: new Date(2009, 0, 1), y: 51, y1: 51, y2: 51, y3: 51 },
{ x: new Date(2010, 0, 1), y: 26, y1: 26, y2: 26, y3: 26 },
{ x: new Date(2011, 0, 1), y: 37, y1: 37, y2: 37, y3: 37 },
{ x: new Date(2012, 0, 1), y: 54, y1: 43, y2: 12, y3: 54 },
{ x: new Date(2013, 0, 1), y: 44, y1: 23, y2: 16, y3: 44 },
{ x: new Date(2014, 0, 1), y: 48, y1: 55, y2: 34, y3: 23 }
];
var chart = new ej.charts.Chart({
primaryXAxis: {
title: 'Years',
valueType: 'DateTime',
intervalType: 'Years',
labelFormat: 'y',
edgeLabelPlacement: 'Shift'
},
primaryYAxis:
{
title: 'Temperature (%)',
labelFormat: '{value}%',
rangePadding: 'None'
},
series: [
{
dataSource: chartData, xName: 'x', yName: 'y',
//Series type as 100% stacked area series
type: 'StackingArea100', dashArray: '5.5',
border: { width: 2, color: 'black' },
name: 'USA',
}, {
dataSource: chartData, xName: 'x', yName: 'y1',
type: 'StackingArea100', name: 'UK', dashArray: '5.5',
border: { width: 2, color: 'black' }
}, {
dataSource: chartData, xName: 'x', yName: 'y2',
type: 'StackingArea100', name: 'Canada', dashArray: '5.5',
border: { width: 2, color: 'black' }
}, {
dataSource: chartData, xName: 'x', yName: 'y3',
type: 'StackingArea100', name: 'China', dashArray: '5.5',
border: { width: 2, color: 'black' }
}
],
title: 'Annual Temperature 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/23.2.4/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.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>