Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dark mode #789

Open
rogerfar opened this issue Mar 28, 2023 · 1 comment
Open

Dark mode #789

rogerfar opened this issue Mar 28, 2023 · 1 comment

Comments

@rogerfar
Copy link

Is it possible to add a dark mode? Or should we manually change the background color?

@AntonioDePau
Copy link

AntonioDePau commented Sep 18, 2023

Hi @rogerfar, you can easily implement dark mode yourself by passing the following options when creating your chart (for a pie chart in this case):

let options = {
    theme: {
        chart: {
            backgroundColor: 'transparent'
        },
        legend: {
            label: {
                color: 'white'
            }
        }
    }
}

let chart = new PieChart({
    el: el,
    data: data,
    options: options
});

If you want to monitor mode/theme changes:

let theme = window.matchMedia("(prefers-color-scheme: dark)");

const applyTheme = (isDarkMode) => {
    options.theme.legend.label.color = isDarkMode ? "white" : "black";
    chart.setOptions(options);
}

// apply theme right after we draw the chart
applyTheme(theme.matches);
        
// monitor theme changes and apply the new theme
theme.addEventListener("change", e => {
    applyTheme(e.matches);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants