Highcharts Pie chart (labels through connector line)

author(s): 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',
                useHTML: true,
                formatter: function() {
                	return `<p style="text-align:center; line-height: 1rem; margin-top: -0.75rem; font-size: 0.75rem;">${this.point.name}<br/>${this.point.y}</p>`
                },
                y: 0,
                connectorShape: function (labelPosition, connectorPosition, options) {
                    var
                        touchingSliceAt = connectorPosition.touchingSliceAt,
                        alignment = labelPosition.alignment,
                        left = 0,
                        right = 0;
                    if (alignment == 'left') {
                        // labels on the right
                        left = labelPosition.x + this.dataLabel.bBox.width + 14
                        right = labelPosition.x + 2
                    } else {
                        // label on the left
                        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
                    ];
              ...