Highcharts Pie Chart Example1
By Dongdong Zhang
by onlyzdd
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container" style="height: 400px; width: 600px;"></div>
JavaScript
Highcharts.chart('container', {
chart: {
borderWidth: 1,
borderColor: '#eee',
plotBorderWidth: 1,
plotShadow: false,
type: 'pie'
},
title: {
text: 'Most World Cup Wins By Country (after 2018 tournament)'
},
tooltip: {
pointFormat: '<b>{point.percentage:.1f}%</b> of all {series.total} cups'
},
plotOptions: {
pie: {
size: '60%',
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
alignTo: 'toPlotEdges',
format: '<b>{point.name}</b>: {point.y}',
y: -14,
connectorShape: function (labelPosition, connectorPosition, options) {
var
touchingSliceAt = connectorPosition.touchingSliceAt,
alignment = labelPosition.alignment,
left = 0,
right = 0;
if (alignment == 'left') {
left = labelPosition.x + this.dataLabel.bBox.width + 14
right = labelPosition.x + 2
} else {
left = labelPosition.x - this.dataLabel.bBox.width - 14
right = labelPosition.x - 2
}
return ['M',
left,
labelPosition.y,
'L',
right,
labelPosition.y,
'L',
touchingSliceAt.x,
touchingSliceAt.y
];
}
}
}
},
series: [{
name: 'Teams',
colorByPoint: true,
data: [{
name: 'Spain',
y: 1
}, {
name: 'Brazil',
y: 5
}, {
name: 'England',
y: 1
...