Highcharts Pie Chart Example2
By Dongdong Zhang
by onlyzdd
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<div style="position:absolute">
<h1 style="position: absolute; top: 20px;">
Today is a nice day!
</h1>
<div id="container" style="height: 400px; width: 600px;"></div>
</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',
useHTML: true,
formatter: function() {
var padding_left = this.point.labelPosition.alignment === 'left' ? '6px' : '-6px';
return `<p style="margin: -8px auto; text-align:center;"><span style="padding-left: ${padding_left}">${this.point.name}</span><br/>${this.point.y}</p>`
},
y: -4,
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 + 18
right = labelPosition.x + 8
} else {
left = labelPosition.x - this.dataLabel.bBox.width - 18
right = labelPosition.x - 8
}
return ['M',
left,
labelPosition.y,
'L',
right,
labelPosition.y,
'L',
touchingSliceAt.x,
touchingSliceAt.y
...