JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<figure class="highcharts-figure">
<div id="container"></div>
<div class="highcharts-description">
This demo uses a tri-state theme selector, where the "Light" option
applies default colors, and the "Dark" option applies CSS variables for
dark colors. The "System default" option applies those color variables
only if <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme">
prefers-color-scheme</a> is <code>dark</code>.
</div>
<div class="controls">
<h4>Color theme</h4>
<label>
<input type="radio" name="color-mode" value="none" checked>
System default
</label>
<label>
<input type="radio" name="color-mode" value="light">
Light
</label>
<label>
<input type="radio" name="color-mode" value="dark">
Dark
</label>
</div>
</figure>
JavaScript
Highcharts.chart('container', {
chart: {
styledMode: true
},
title: {
text: 'Styling with prefers-color-scheme'
},
xAxis: {
width: '40%',
type: 'category'
},
yAxis: {
width: '40%',
title: {
text: 'kg'
}
},
series: [{
type: 'pie',
allowPointSelect: true,
keys: ['name', 'y', 'selected', 'sliced'],
data: [
['Apples', 29.9, false],
['Pears', 71.5, false],
['Oranges', 106.4, false],
['Plums', 129.2, false],
['Bananas', 144.0, false],
['Peaches', 176.0, false],
['Prunes', 135.6, true, true],
['Avocados', 148.5, false]
],
showInLegend: true,
center: ['75%', '50%']
}, {
type: 'column',
keys: ['name', 'y'],
data: [
['Apples', 29.9, false],
['Pears', 71.5, false],
['Oranges', 106.4, false],
['Plums', 129.2, false],
['Bananas', 144.0, false],
['Peaches', 176.0, false],
['Prunes', 135.6, true, true],
['Avocados', 148.5, false]
],
colorByPoint: true,
showInLegend: false
}]
});
[...document.querySelectorAll('input[name="color-mode"]')]
.forEach(input => {
input.addEventListener('click', e => {
document.getElementById('container').className =
e.target.value === 'none' ? '' : `highcharts-${e.target.value}`;
});
});