Basic donut
by oysteinmoseng
December 19, 2024
HTML
<script src="https://code.highcharts.com/highcharts.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;
}
.highcharts-description {
margin: 0.3rem 10px;
}
JavaScript
Highcharts.chart('container', {
chart: {
type: 'pie',
backgroundColor: '#222'
},
title: {
text: 'Charity allocations',
style: {
color: '#fff'
}
},
colors: ['#4CAF50', '#E94E77', '#5BC0EB', '#FDE74C', '#FFA07A', '#A9A9A9'],
tooltip: {
valueSuffix: '%'
},
series: [{
name: 'Allocation',
colorByPoint: true,
borderColor: '#222',
borderWidth: 3,
borderRadius: 8, // Rounded slice corners
innerSize: '60%', // Turning the pie into a donut
dataLabels: {
format: '{point.name}: {point.percentage:.0f}%'
},
data: [
['Health care', 34],
['Education', 27],
['Youth programmes', 22],
['Poverty measures', 8],
['Elderly care', 6],
['Other', 3]
]
}]
});