Themes API
Control chart light/dark mode with theme / setTheme(), and optionally set an exact background hex via themeColor.
Interactive lab
Open examples/themes-lab.html (from the SDK package root: npm run serve, then http://127.0.0.1:8080/examples/themes-lab.html ) to verify:
- Construct with
theme: "light"/"dark" - Runtime
setTheme("light" | "dark") - Optional
themeColorhex (including custom colors) - Explicit construct options vs
localStoragegocharting-theme-color - Live demo WebSocket bars (
wss://gocharting.com/sdk/ws)
Preferred API: theme
Pass "light" or "dark" to createChart() (or the <GoCharting /> component).
When themeColor is omitted, the SDK maps:
theme | Default themeColor |
|---|---|
"light" | #ffffff |
"dark" | #22292f |
import { createChart } from "@gocharting/chart-sdk";
const chart = createChart("#chart", {
symbol: "BYBIT:FUTURE:BTCUSDT",
interval: "1D",
datafeed: myDatafeed,
licenseKey: "YOUR_LICENSE_KEY",
theme: "dark",
});Runtime: setTheme()
chart.setTheme("light" | "dark"): voidchart.setTheme("dark");Toggle example:
let mode = "light";
document.getElementById("theme-toggle").addEventListener("click", () => {
mode = mode === "light" ? "dark" : "light";
chart.setTheme(mode);
});Optional: themeColor (hex background)
themeColor is a CSS hex color for the app chrome (e.g. #22292f, #570f0f).
It is not "light" or "dark" — use theme for that.
Any #RRGGBB value is supported. Built-in tuned palettes also exist for:
#ffffff, #22292f, #e3342f, #f6993f, #ffed4a, #38c172, #4dc0b5, #3490dc, #6574cd, #9561e2, #f66d9b.
createChart("#chart", {
symbol: "BYBIT:FUTURE:BTCUSDT",
interval: "1D",
datafeed: myDatafeed,
licenseKey: "YOUR_LICENSE_KEY",
themeColor: "#570f0f", // arbitrary hex chrome tint
});Rules of thumb:
- Prefer
themeonly for normal light/dark switching. - Use
themeColorwhen you need a specific background hex. - Explicit
theme/themeColoroncreateChartwin over a savedgocharting-theme-colorinlocalStorage. setTheme("light"|"dark")switches the named mode at runtime (maps to#ffffff/#22292f).
Construct-time options (advanced)
For deeper chrome styling beyond light/dark:
| Option | Role |
|---|---|
custom_css_url | Inject an external stylesheet |
custom_themes | CSS variable / token map applied at construct time |
toolbar_bg | Toolbar background CSS variable |
overrides / applyOverrides | Chart appearance (canvas), not the same as theme |
See Configuration for full option lists.
System preference
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
const chart = createChart("#chart", {
symbol: "BYBIT:FUTURE:BTCUSDT",
interval: "1D",
datafeed: myDatafeed,
licenseKey: "YOUR_LICENSE_KEY",
theme: prefersDark ? "dark" : "light",
});
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", (e) => {
chart.setTheme(e.matches ? "dark" : "light");
});Reference
| Option / method | Type | Description |
|---|---|---|
theme | "light" | "dark" | Named theme (preferred) |
themeColor | string (hex/CSS color) | Optional background override — not "light"/"dark" |
setTheme(mode) | (mode: "light" | "dark") => void | Switch theme after create |
Related
- Configuration — full construct options
- Chart API —
createChart/ widget methods - GoCharting component — React props (
theme,themeColor)