// Define custom theme objects for light and dark mode.
const lightTheme = {
// Colors for the series. For two columns we set pink and yellow.
colors: ['pink', 'yellow'],
chart: {
backgroundColor: '#ffffff', // white background for light mode
style: {
fontFamily: 'Arial, sans-serif',
color: '#000000'
}
},
title: {
style: {
color: '#000000'
}
}
};
const darkTheme = {
// Colors for the series. For two columns we set blue and purple.
colors: ['blue', 'purple'],
chart: {
backgroundColor: '#333333', // dark background
style: {
fontFamily: 'Arial, sans-serif',
color: '#ffffff'
}
},
title: {
style: {
color: '#ffffff'
}
}
};
let chart; // Will hold our chart instance
// This function returns the appropriate theme object based on the user's choice.
function getTheme(selectedTheme) {
if (selectedTheme === 'light') {
return lightTheme;
} else if (selectedTheme === 'dark') {
return darkTheme;
} else { // 'system'
// Check system setting using prefers-color-scheme
const isDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
return isDark ? darkTheme : lightTheme;
}
}
// Function to render (or re-render) the chart
function renderChart() {
// Get the currently selected theme from the radio buttons
const selectedTheme = document.querySelector('input[name="theme"]:checked').value;
const theme = getTheme(selectedTheme);
// If a chart exists, destroy it before re-creating
if (chart) {
chart.destroy();
}
// Create a new Highcharts chart using the theme options.
chart = Highcharts.chart('container', {
chart: Object.assign({}, theme.chart, { type: 'column' }),
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.