To render a 100% stacked line series, use series type
as
StackingLine100
and inject StackingLineSeries
module using Chart.Inject(StackingLineSeries)
method.
import { Chart, Category, Legend, Tooltip, StackingLineSeries } from '@syncfusion/ej2-charts';
import { Browser } from '@syncfusion/ej2-base';
Chart.Inject(StackingLineSeries, Category, Legend, Tooltip);
/**
* Sample for StackedLine Series
*/
let chartData: Object[] = [
{ x: 'Food', y: 90, y1: 40, y2: 70, y3: 120 },
{ x: 'Transport', y: 80, y1: 90, y2: 110, y3: 70 },
{ x: 'Medical', y: 50, y1: 80, y2: 120, y3: 50 },
{ x: 'Clothes', y: 70, y1: 30, y2: 60, y3: 180 },
{ x: 'Personal Care', y: 30, y1: 80, y2: 80, y3: 30 },
{ x: 'Books', y: 10, y1: 40, y2: 30, y3: 270 },
{ x: 'Fitness', y: 100, y1: 30, y2: 70, y3: 40 },
{ x: 'Electricity', y: 55, y1: 95, y2: 55, y3: 75 },
{ x: 'Tax', y: 20, y1: 50, y2: 40, y3: 65 },
{ x: 'Pet Care', y: 40, y1: 20, y2: 80, y3: 95 },
{ x: 'Education', y: 45, y1: 15, y2: 45, y3: 195 },
{ x: 'Entertainment', y: 75, y1: 45, y2: 65, y3: 115 }
];
let chart: Chart = new Chart({
primaryXAxis: {
interval: 1, valueType: 'Category'
},
primaryYAxis:
{
interval: 20
},
chartArea: { border: { width: 0 } },
series: [
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
dashArray: '5, 1', xName: 'x', width: 2, yName: 'y', name: 'John'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
dashArray: '5, 1', xName: 'x', width: 2, yName: 'y1', name: 'Peter'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
dashArray: '5, 1', xName: 'x', width: 2, yName: 'y2', name: 'Steve'
},
{
type: 'StackingLine100', dataSource: chartData, marker: { visible: true },
dashArray: '5, 1', xName: 'x', width: 2, yName: 'y3', name: 'Charle'
}
],
tooltip: {
enable: true,
format: '${point.x} : <b>${point.y} (${point.percentage}%)</b>'
}
}, '#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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>
The following properties can be used to customize the 100% stacked line
series.
fill
– Specifies the color of the series.opacity
– Specifies the opacity of fill
.dashArray
– Specifies the dashes for series.width
– Specifies the width for series.import { Chart, StackingLineSeries } from '@syncfusion/ej2-charts';
import { numData } from './datasource.ts';
Chart.Inject(StackingLineSeries);
let chartData: Object[] = [
{ x: 2005, y: 90, y1: 40, y2: 70, y3: 120 },
{ x: 2006, y: 80, y1: 90, y2: 110, y3: 70 },
{ x: 2007, y: 50, y1: 80, y2: 120, y3: 50 },
{ x: 2008, y: 70, y1: 30, y2: 60, y3: 180 },
{ x: 2009, y: 30, y1: 80, y2: 80, y3: 30 },
{ x: 2010, y: 10, y1: 40, y2: 30, y3: 270 },
{ x: 2011, y: 100, y1: 30, y2: 70, y3: 40 }];
let chart: Chart = new Chart({
series:[ {
dataSource: chartData,
fill: 'green',width: 2,
dashArray: '2',xName: 'x',marker: {visible: true},
yName: 'y',type: 'StackingLine100',
},
{
dataSource: chartData,
fill: 'pink',width: 2,
dashArray: '2',xName: 'x',marker: {visible: true},
yName: 'y1',type: 'StackingLine100',
type: 'StackingLine100',
},
{
dataSource: chartData,
fill: 'yellow',width: 2,
dashArray: '2',xName: 'x',marker: {visible: true},
yName: 'y2',type: 'StackingLine100',
},
{
dataSource: chartData,
fill: 'red',width: 2,
dashArray: '2',xName: 'x',marker: {visible: true},
yName: 'y3',type: 'StackingLine100',
}],
}, '#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>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
</body>
</html>