Pie chart

author(s): Torstein Hønsi

by oysteinmoseng

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/accessibility.js"></script>
<script src="https://code.highcharts.com/themes/high-contrast-dark.js"></script>

<figure class="highcharts-figure">
    <div id="container"></div>
</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: {
        type: 'pie'
    },
    title: {
        text: null
    },
    exporting: {
    	sourceWidth: 1000,
        sourceHeight: 500
    },
    plotOptions: {
        pie: {
            dataLabels: {
                enabled: true,
                format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                style: {
                	fontSize: 14
                }
            },
            borderColor: '#2B2B2B',
            borderWidth: 3
        }
    },
    credits: {
    	enabled: false
    },
    series: [{
        name: 'Time spent',
        colorByPoint: true,
        data: [{
            name: 'My presentation',
            y: 1,
        }, {
            name: 'Working from hotel room',
            y: 9
        }, {
            name: "Other people's presentations",
            y: 17
        }, {
            name: 'Meetings & networking',
            y: 28
        }]
    }]
});