Highcharts Demo
author(s):
Torstein Hønsi
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/no-data-to-display.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container"></div>
<button id="add" class="highcharts-demo-button">Add data</button>
<button id="remove" class="highcharts-demo-button">Remove data</button>
CSS
#container {
min-width: 310px;
height: 400px;
margin: 0 auto;
}
.highcharts-demo-button {
background: var(--highcharts-neutral-color-5, #f2f2f2);
border: none;
border-radius: 4px;
color: var(--highcharts-neutral-color-100, #000);
cursor: pointer;
display: inline-block;
font-size: 0.8rem;
padding: 0.5rem 1.5rem;
margin: 0.5rem -5px 0.5rem 10px;
transition: background 250ms;
}
.highcharts-demo-button:hover {
background: var(--highcharts-neutral-color-10, #e6e6e6);
}
JavaScript
const chart = Highcharts.chart('container', {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'No data in pie chart'
},
series: [{
type: 'pie',
name: 'Random data',
data: []
}]
});
document.getElementById('add').addEventListener('click', () => {
chart.series[0].addPoint(Math.floor(Math.random() * 10 + 1)); // Return
// random integer between 1 and 10.
});
document.getElementById('remove').addEventListener('click', () => {
if (chart.series[0].points[0]) {
chart.series[0].points[0].remove();
}
});