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
const chart = Highcharts.chart('container', {
chart: {
type: 'pie',
height: 320,
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
},
title: {
text: 'Circuit House Bookings'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.count}</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
// dataLabels: {
// enabled: true,
// format: '<b>{point.name}</b>: {point.count}'
// }
}
},
exporting: {
buttons: {
contextButton: {
menuItems: ['viewFullscreen', 'separator', 'downloadPNG', 'downloadJPEG', 'downloadPDF', 'downloadSVG']
}
}
},
series: [{
name: 'Count',
colorByPoint: true,
data: [
{name: 'Confirmed', y: 72},
{name: 'Pending', y: 0},
{name: 'Dept. Cancelled', y: 2},
{name: 'Guest Cancelled', y: 1},
{name: 'Rejected', y: 9},
]
}]
});