Pie chart

author(s): Torstein Hønsi

by Sree K

HTML

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>

<figure class="highcharts-figure">
    <div id="container"></div>
    <p class="highcharts-description">
        Pie charts are very popular for showing a compact overview of a
        composition or comparison. While they can be harder to read than
        column charts, they remain a popular choice for small datasets.
    </p>
</figure>

CSS

.highcharts-figure,
.highcharts-data-table table {
    min-width: 320px;
    max-width: 800px;
    margin: 1em auto;
}

.highcharts-data-table table {
    font-family: Verdana, sans-serif;
    border-collapse: collapse;
    border: 1px solid #ebebeb;
    margin: 10px auto;
    text-align: center;
    width: 100%;
    max-width: 500px;
}

.highcharts-data-table caption {
    padding: 1em 0;
    font-size: 1.2em;
    color: #555;
}

.highcharts-data-table th {
    font-weight: 600;
    padding: 0.5em;
}

.highcharts-data-table td,
.highcharts-data-table th,
.highcharts-data-table caption {
    padding: 0.5em;
}

.highcharts-data-table thead tr,
.highcharts-data-table tr:nth-child(even) {
    background: #f8f8f8;
}

.highcharts-data-table tr:hover {
    background: #f1f7ff;
}

input[type="number"] {
    min-width: 50px;
}

JavaScript

Highcharts.chart('container', {
    chart: {
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false,
        type: 'pie'
    },
    title: {
        text: 'Browser market shares in January, 2018'
    },
    tooltip: {
        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
    },
    accessibility: {
        point: {
            valueSuffix: '%'
        }
    },
    plotOptions: {
        pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: {
                enabled: true,
                format: '<b>{point.name}</b>: {point.percentage:.1f} %'
            }
        }
    },
    series: [{
        name: 'Brands',
        colorByPoint: true,
        data: [{
            name: 'Brand 1',
            y: 61.41,
            sliced: true,
            selected: true
        }, {
            name: 'Brand 2',
            y: 11.84
        }, {
            name: 'Brand 3',
            y: 10.85
        }, {
            name: 'Brand 4',
            y: 4.67
        }, {
            name: 'Brand 5',
            y: 4.18
        }, {
            name: 'Brand 6',
            y: 1.64
        }, {
            name: 'Brand 7',
            y: 1.6
        }, {
            name: 'Brand 8',
            y: 1.2
        }, {
            name: 'Brand 9',
            y: 2.61
        }]
    }, {
        name: 'Sub Brands',
        colorByPoint: true,
        data: [{
            name: 'Sub Brand 1',
            y: 21.41,
            sliced: true,
            selected: true
        }, {
            name: 'Sub Brand 2',
            y: 6.84
        }, {
            name: 'Sub Brand 3',
            y: 6.85
        }, {
            name: 'Sub Brand 4',
            y: 1.67
        }, {
            name: 'Sub Brand 5',
            y: 5.18
        }, {
            name: 'Sub Brand 6',
            y: 0.64
        }, {
            name: 'Sub Brand 7',
            y: 0.6
        }, {
            name: 'Sub Brand...