Search

Dark Mode

Chart Options

Explore dark background and navigation for dark theme charts.

Dark Mode
View live example →

Use the Toggle theme button to switch between light and dark modes.

For charts in dark mode, set a dark backgroundColor and change the theme for navigation controls and the overview window with the controlTheme property of the options prop.

See also

import React, { useState } from "react";
import { createRoot } from "react-dom/client";

import { Chart } from "regraph";

import { darkButtonStyle } from "./data";
import { style } from "@ci/theme/rg/js/storyStyles";

export const Demo = () => <DarkMode />;

const styles = {
  dark: { backgroundColor: style.colors.darkCharcoal },
  light: { backgroundColor: style.colors.pureWhite },
};

function DarkMode() {
  const [theme, setTheme] = useState("dark");

  const { backgroundColor } = styles[theme];

  return (
    <div className="story">
      <div className="options" style={{ backgroundColor }}>
        <button
          type="button"
          onClick={() => {
            setTheme(theme === "dark" ? "light" : "dark");
          }}
          style={theme === "dark" ? darkButtonStyle : {}}
        >
          Toggle theme
        </button>
      </div>
      <div className="chart-wrapper">
        <Chart options={{ backgroundColor, controlTheme: theme, overview: true }} />
      </div>
    </div>
  );
}

const root = createRoot(document.getElementById("regraph"));
root.render(<Demo />);
export const darkButtonStyle = {
  backgroundColor: "rgb(45, 56, 64)",
  color: "rgb(229, 232, 235)",
  borderWidth: 1,
  borderColor: "rgb(112,118,126)",
};
<!doctype html>
<html>
  <body>
    <div id="regraph" style="height: 100vh"></div>
    <script type="module" src="./code.jsx"></script>
  </body>
</html>

Terms of use

These terms do not alter or supersede any existing agreements between you (or your employer) and us.

By accessing or using any Content you agree to be bound by these Terms of Use. Please review these terms carefully before using the website.

The contents of this website, including but not limited to any text, code samples, API references, schemas, interactive tools, and other materials (collectively, the 'Content'), are made available for informational and internal evaluation purposes only. All intellectual property rights in the Content are reserved. No licence is granted to use the Content for any commercial purpose, or to copy, distribute, modify, reverse-engineer, or incorporate any part of the Content into any product or service, without our prior written consent.

This Content is provided “as is” and “as available,” without any representations, warranties, or guarantees of any kind, whether express or implied, including but not limited to implied warranties of merchantability, fitness for a particular purpose, non-infringement, or accuracy. To the fullest extent permitted by applicable law, we expressly exclude and disclaim all implied warranties, conditions, and other terms that might otherwise be implied.

We disclaim all liability for any loss or damage, whether direct, indirect, incidental, consequential, or otherwise, arising from any reliance placed on the Content or from your use of it, to the fullest extent permitted by applicable law. By continuing to access or use the Content, you acknowledge and agree to these terms.