Contents
- Hover text
- Customization
Having trouble getting help?
Contact Support
Contact Support
Center label in EJ2 TypeScript Accumulation chart control
8 May 202311 minutes to read
Using centerLabel
it is now possible to place a label at the center of a pie or doughnut chart. To configure the default text rendered on the center label for the pie and doughnut charts, use the text
property in the centerLabel
.
import { AccumulationChart } from '@syncfusion/ej2-charts';
import { data } from './datasource.ts';
let piechart: AccumulationChart = new AccumulationChart({
series: [
{
dataSource: [ { x: 'Chrome', y: 61.3, text: 'Chrome: 61.3%' },
{ x: 'Safari', y: 24.6, text: 'Safari: 24.6%' },
{ x: 'Edge', y: 5.0, text: 'Edge: 5.0%' },
{ x: 'Samsung Internet', y: 2.7, text: 'Samsung Internet: 2.7%' },
{ x: 'Firefox', y: 2.6, text: 'Firefox: 2.6%' },
{ x: 'Others', y: 3.6, text: 'Others: 3.6%' }],
innerRadius: '65%',
xName: 'x',
yName: 'y'
}
],
centerLabel:{
text : 'Mobile<br>Browsers<br>Statistics'
}
}, '#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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
<script id="Unemployment" type="text/x-template">
<div id='templateWrap'>
<table style="width:100%; border: 1px solid black;">
<tr><th colspan="2" bgcolor="#00FFFF">Unemployment</th></tr>
<tr><td bgcolor="#00FFFF">${x}:</td><td bgcolor="#00FFFF">${y}</td></tr>
</table>
</div>
</script>
</body>
</html>
Hover text
The default text in the center label can be changed when the mouse pointer hovers over the pie and doughnut charts slice using the hoverTextFormat
property.
import { AccumulationChart } from '@syncfusion/ej2-charts';
import { data } from './datasource.ts';
let piechart: AccumulationChart = new AccumulationChart({
series: [
{
dataSource: [ { x: 'Chrome', y: 61.3, text: 'Chrome: 61.3%' },
{ x: 'Safari', y: 24.6, text: 'Safari: 24.6%' },
{ x: 'Edge', y: 5.0, text: 'Edge: 5.0%' },
{ x: 'Samsung Internet', y: 2.7, text: 'Samsung Internet: 2.7%' },
{ x: 'Firefox', y: 2.6, text: 'Firefox: 2.6%' },
{ x: 'Others', y: 3.6, text: 'Others: 3.6%' }],
innerRadius: '65%',
xName: 'x',
yName: 'y'
}
],
centerLabel:{
text : 'Mobile<br>Browsers<br>Statistics',
hoverTextFormat: '${point.x} <br> Browser Share <br> ${point.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://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
<script id="Unemployment" type="text/x-template">
<div id='templateWrap'>
<table style="width:100%; border: 1px solid black;">
<tr><th colspan="2" bgcolor="#00FFFF">Unemployment</th></tr>
<tr><td bgcolor="#00FFFF">${x}:</td><td bgcolor="#00FFFF">${y}</td></tr>
</table>
</div>
</script>
</body>
</html>
Customization
Customize the center label text using the textStyle
property.
import { AccumulationChart } from '@syncfusion/ej2-charts';
import { data } from './datasource.ts';
let piechart: AccumulationChart = new AccumulationChart({
series: [
{
dataSource: [ { x: 'Chrome', y: 61.3, text: 'Chrome: 61.3%' },
{ x: 'Safari', y: 24.6, text: 'Safari: 24.6%' },
{ x: 'Edge', y: 5.0, text: 'Edge: 5.0%' },
{ x: 'Samsung Internet', y: 2.7, text: 'Samsung Internet: 2.7%' },
{ x: 'Firefox', y: 2.6, text: 'Firefox: 2.6%' },
{ x: 'Others', y: 3.6, text: 'Others: 3.6%' }],
innerRadius: '65%',
xName: 'x',
yName: 'y'
}
],
centerLabel:{
text : 'Mobile<br>Browsers<br>Statistics',
textStyle:{
fontWeight: '900',
size: '15px',
color: 'grey',
fontFamily: 'Roboto',
fontStyle: 'Italic'
}
}
}, '#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>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container'>
<div id='element'></div>
</div>
<script id="Unemployment" type="text/x-template">
<div id='templateWrap'>
<table style="width:100%; border: 1px solid black;">
<tr><th colspan="2" bgcolor="#00FFFF">Unemployment</th></tr>
<tr><td bgcolor="#00FFFF">${x}:</td><td bgcolor="#00FFFF">${y}</td></tr>
</table>
</div>
</script>
</body>
</html>