To render a pie series, use the series type
as Pie
and
inject the PieSeries
module using AccumulationChart.Inject(PieSeries)
method. If the PieSeries
module is not
injected, this module will be loaded by default.
var piechart = new ej.charts.AccumulationChart({
series: [
{
dataSource: [{ x: 'Jan', y: 3 }, { x: 'Feb', y: 3.5 }, { x: 'Mar', y: 7 }, { x: 'Apr', y: 13.5 },
{ x: 'May', y: 19 }, { x: 'Jun', y: 23.5 }, { x: 'Jul', y: 26 }, { x: 'Aug', y: 25 },
{ x: 'Sep', y: 21 }, { x: 'Oct', y: 15 }],
radius: '100%',
xName: 'x',
yName: 'y'
}
],
tooltip:{enable: true}
}, '#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>
By default, radius of the pie series will be 80% of the size (minimum of chart width and height).
You can customize this using radius
property of the series.
var piechart = new ej.charts.AccumulationChart({
series: [
{
dataSource: [{ x: 'Jan', y: 3 }, { x: 'Feb', y: 3.5 }, { x: 'Mar', y: 7 }, { x: 'Apr', y: 13.5 },
{ x: 'May', y: 19 }, { x: 'Jun', y: 23.5 }, { x: 'Jul', y: 26 }, { x: 'Aug', y: 25 },
{ x: 'Sep', y: 21 }, { x: 'Oct', y: 15 }],
radius: '100%',
xName: 'x',
yName: 'y'
}
],
tooltip:{enable: true}
}, '#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 center position of the pie can be changed by Center X and Center Y. By default, center value of the pie series x and y is 50%. You can customize this using center
property of the series.
var piechart = new ej.charts.AccumulationChart({
series: [
{
dataSource: [{ x: 'Jan', y: 3 }, { x: 'Feb', y: 3.5 }, { x: 'Mar', y: 7 }, { x: 'Apr', y: 13.5 },
{ x: 'May', y: 19 }, { x: 'Jun', y: 23.5 }, { x: 'Jul', y: 26 }, { x: 'Aug', y: 25 },
{ x: 'Sep', y: 21 }, { x: 'Oct', y: 15 }],
radius: '100%',
xName: 'x',
yName: 'y',
enter: {x: '60%', y: '60%'},
}
],
tooltip:{enable: true}
}, '#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>
You can use radius mapping to render the slice with different radius
pie and also use border
, fill properties to customize the point. dataLabel is used to represent individual data and its value.
var piechart = new ej.charts.AccumulationChart({
series: [
{
dataSource: [
{ x: 'Argentina', y: 505370, r: '100' },
{ x: 'Belgium', y: 551500, r: '118.7' },
{ x: 'Cuba', y: 312685, r: '124.6' },
{ x: 'Dominican Republic', y: 350000, r: '137.5' },
{ x: 'Egypt', y: 301000, r: '150.8' },
{ x: 'Kazakhstan', y: 300000, r: '155.5' },
{ x: 'Somalia', y: 357022, r: '160.6' }
],
dataLabel: {
visible: true, position: 'Outside',
name: 'x'
},
radius: 'r', xName: 'x',
yName: 'y', innerRadius: '20%'
},
],
enableSmartLabels: true,
legendSettings: {
visible: true,
},
enableAnimation: true,
title: 'Countries compared by population density and total area'
}, '#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>
To achieve a doughnut in pie series, customize the innerRadius
property of the series. By setting value greater than 0%, a doughnut will appear.
The innerRadius
property takes value from 0% to 100% of the pie radius.
var piechart = new ej.charts.AccumulationChart({
series: [
{
dataSource: [{ x: 'Jan', y: 3 }, { x: 'Feb', y: 3.5 }, { x: 'Mar', y: 7 }, { x: 'Apr', y: 13.5 },
{ x: 'May', y: 19 }, { x: 'Jun', y: 23.5 }, { x: 'Jul', y: 26 }, { x: 'Aug', y: 25 }],
innerRadius: '40%',
xName: 'x',
yName: 'y'
}
]
}, '#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>
You can customize the start and end angle of the pie series using the
startAngle
and
endAngle
properties. The default value of startAngle
is 0 degree,
and endAngle
is 360 degrees. By customizing this, you can achieve a semi pie series.
var piechart = new ej.charts.AccumulationChart({
series: [
{
dataSource: [
{ x: 'Jan', y: 3, text: 'Jan: 3' }, { x: 'Feb', y: 3.5, text: 'Feb: 3.5' },
{ x: 'Mar', y: 7, text: 'Mar: 7' }, { x: 'Apr', y: 13.5, text: 'Apr: 13.5' },
{ x: 'May', y: 19, text: 'May: 19' }, { x: 'Jun', y: 23.5, text: 'Jun: 23.5' },
{ x: 'Jul', y: 26, text: 'Jul: 26' }, { x: 'Aug', y: 25, text: 'Aug: 25' },
{ x: 'Sep', y: 21, text: 'Sep: 21' }, { x: 'Oct', y: 15, text: 'Oct: 15' }],
dataLabel: { visible: true, name: 'text', position: 'Outside' },
startAngle: 270,
endAngle: 90,
xName: 'x',
yName: 'y'
}
]
}, '#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 fill color and the text in the data source can be mapped to the chart using pointColorMapping
in series and
name
in datalabel respectively.
var piechart = new ej.charts.AccumulationChart({
series: [
{
dataSource: [
{ x: 'Jan', y: 3, text: 'Jan: 3' }, { x: 'Feb', y: 3.5, text: 'Feb: 3.5' },
{ x: 'Mar', y: 7, text: 'Mar: 7' }, { x: 'Apr', y: 13.5, text: 'Apr: 13.5' },
{ x: 'May', y: 19, text: 'May: 19' }, { x: 'Jun', y: 23.5, text: 'Jun: 23.5' },
{ x: 'Jul', y: 26, text: 'Jul: 26' }, { x: 'Aug', y: 25, text: 'Aug: 25' },
{ x: 'Sep', y: 21, text: 'Sep: 21' }, { x: 'Oct', y: 15, text: 'Oct: 15' }],
dataLabel: { visible: true, name: 'text', position: 'Outside' },
startAngle: 270,
endAngle: 90,
xName: 'x',
yName: 'y'
}
]
}, '#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>
Individual points can be customized using the pointRender
event.
var piechart = new ej.charts.AccumulationChart({
series: [
{
dataSource: [
{ x: 'Jan', y: 3, text: 'Jan: 3' }, { x: 'Feb', y: 3.5, text: 'Feb: 3.5' },
{ x: 'Mar', y: 7, text: 'Mar: 7' }, { x: 'Apr', y: 13.5, text: 'Apr: 13.5' },
{ x: 'May', y: 19, text: 'May: 19' }, { x: 'Jun', y: 23.5, text: 'Jun: 23.5' },
{ x: 'Jul', y: 26, text: 'Jul: 26' }, { x: 'Aug', y: 25, text: 'Aug: 25' },
{ x: 'Sep', y: 21, text: 'Sep: 21' }, { x: 'Oct', y: 15, text: 'Oct: 15' },
{ x: 'Nov', y: 9, text: 'Nov: 9' }, { x: 'Dec', y: 3.5, text: 'Dec: 3.5' }],
dataLabel: { visible: true, name: 'text', position: 'Outside' },
groupTo: '11',
xName: 'x',
yName: 'y'
}
],
textRender: (args: IAccTextRenderEventArgs) => {
if (args.text.indexOf('Others') > -1) {
args.color = 'red';
args.border.width = 1;
}
},
pointRender: (args: IAccPointRenderEventArgs) => {
if ((args.point.x as string).indexOf('Others') > -1) {
args.fill = '#D3D3D3';
}
},
}, '#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>
By default, the border will appear in the pie/doughnut chart while mouse hover on the chart. You can disable the the border by
setting enableBorderOnMouseMove
property is false
.
var dataMapping = [{ x: 'Jan', y: 3, fill: '#498fff', text:'January' }, { x: 'Feb', y: 3.5, fill: '#ffa060', text: 'February' },
{ x: 'Mar', y: 7, fill: '#ff68b6', text: 'March' }, { x: 'Apr', y: 13.5, fill: '#81e2a1', text: 'April' }];
var chart = new ej.charts.AccumulationChart({
enableBorderOnMouseMove: false,
series: [
{
dataSource: dataMapping,
xName: 'x',
yName: 'y',
}
]
}, '#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>
You can achieve a multi-level drill down in pie and doughnut charts using pointClick event. If user clicks any point in the chart, that corresponding data will be shown in the next level and so on based on point clicked.
You can also achieve drill-up (back to the initial state) by using chartMouseClick event. In below sample, you can drill-up by clicking back button in the center of the chart.
window.pointIndex = -1;
var data = [
{
x: 'SUV',
y: 25,
z: [
{
title: 'Automobile Sales in the SUV Segment',
x: 'Toyota',
y: 8,
z: [
{ x: '2000', y: 20 },
{ x: '2001', y: 30 },
{ x: '2002', y: 40 },
],
},
{ x: 'Ford', y: 12 },
{ x: 'GM', y: 17 },
{ x: 'Renault', y: 6 },
],
},
{
x: 'Car',
y: 37,
z: [
{ title: 'Automobile Sales in the Car Segment', x: 'Toyota', y: 7 },
{ x: 'Chrysler', y: 12 },
{ x: 'Nissan', y: 9 },
{ x: 'Ford', y: 15 },
],
},
{
x: 'Pickup',
y: 15,
z: [
{ title: 'Automobile Sales in the Pickup Segment', x: 'Nissan', y: 9 },
{ x: 'Chrysler', y: 4 },
{ x: 'Ford', y: 7 },
{ x: 'Toyota', y: 20 },
],
},
{
x: 'Minivan',
y: 23,
z: [
{ title: 'Automobile Sales in the Minivan Segment', x: 'Hummer', y: 11 },
{ x: 'Ford', y: 5 },
{ x: 'GM', y: 12 },
{ x: 'Chrysler', y: 3 },
],
},
];
var click = function (args) {
if (pie.series[0].name !== 'Level 3') {
switch (args.pointIndex) {
case 0:
pie.series[0].dataSource = data[0].z[0].z;
pie.title = 'SUV Sales by Years';
pie.series[0].name = 'Level 3';
grid.columns[0].headerText = 'Year';
grid.refresh();
pie.refresh();
break;
}
grid.dataSource = pie.series[0].dataSource;
}
};
var pointClick = function (args) {
if ( ej.charts.getElement( pie.element.id + '_Series_' + args.seriesIndex + '_Point_' + args.pointIndex)) {
pie.series[0].dataSource = data[args.pointIndex].z;
pie.title = data[args.pointIndex].z[0].title;
window.pointIndex = args.pointIndex;
pie.series[0].name = 'Level 2';
pie.series[0].innerRadius = '30%';
pie.annotations = [
{
content:
'<div id="back" style="cursor:pointer;padding:3px;width:30px; height:30px;">' +
'<img src="https://ej2.syncfusion.com/javascript/demos/src/chart/images/back.png" id="back" />',
region: 'Series',
x: '50%',
y: '50%',
},
];
pie.pointClick = click;
var secondlevelpie = pie;
}
grid.dataSource = pie.series[0].dataSource;
grid.columns[0].headerText = data[args.pointIndex].x;
grid.refresh();
pie.refresh();
};
var instance = {
series: [
{
dataSource: data,
dataLabel: {
visible: true,
position: 'Inside',
},
radius: '70%',
xName: 'x',
yName: 'y',
startAngle: 0,
endAngle: 360,
innerRadius: '0%',
name: 'Level 1',
},
],
enableSmartLabels: false,
legendSettings: { visible: true },
chartMouseClick: (args) => {
if (args.target.indexOf('back') > -1) {
if (pie.series[0].name === 'Level 3') {
pie.series[0].dataSource = data[window.pointIndex].z;
pie.series[0].name = 'Level 2';
pie.title = data[window.pointIndex].z[0].title;
pie.series[0].innerRadius = '30%';
grid.dataSource = pie.series[0].dataSource;
grid.columns[0].headerText = data[window.pointIndex].x;
grid.refresh();
pie.refresh();
} else if (pie.series[0].name === 'Level 2') {
pie.series[0].dataSource = data;
pie.series[0].name = 'Level 1';
pie.series[0].innerRadius = '0%';
pie.title = 'Automobile Sales by Category';
pie.annotations = [{}];
pie.pointClick = pointClick;
grid.dataSource = pie.series[0].dataSource;
grid.columns[0].headerText = 'Vehicle';
grid.refresh();
pie.refresh();
}
}
grid.dataSource = pie.series[0].dataSource;
},
pointClick: pointClick,
title: 'Automobile Sales by Category',
};
var pie = new ej.charts.AccumulationChart(instance);
pie.appendTo('#element');
var grid = new ej.grids.Grid({
dataSource: data,
columns: [
{ field: 'x', headerText: 'Vehicle', type: 'string' },
{ field: 'y', headerText: 'Sales', type: 'string' },
],
});
grid.appendTo('#Grid');
<!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="https://cdn.syncfusion.com/ej2/21.2.3/material.css" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/21.2.3/dist/ej2.min.js" type="text/javascript"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
</head>
<body>
<div class="control-section">
<div id="link">
<a id="category" style="visibility:hidden; display:inline-block">
Sales by Category
</a>
<p style="visibility:hidden; display:inline-block" id="symbol"> >> </p>
<p id="text" style="display:inline-block;"></p>
</div>
<div id="container"></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>