Colors and themes
Every color of a chart comes from CSS variables, on SVG and on canvas alike: one stylesheet themes them, dark mode is a media query, and print works.
Three themes, one chart
Each box only sets variables on a wrapper element. The chart and its tooltip follow.
HTML
<script src="/release/kits/basic.js"></script>
<script type="application/json" id="bc-data">
{"sales":[{"region":"North","total":42000},{"region":"South","total":58000},{"region":"East","total":31000},{"region":"West","total":66000}]}
</script>
<div class="cols">
<div class="demo theme-warm"><script type="application/json" data-bc-chart>
{
"data": "sales",
"size": [520, 220],
"scales": { "x": { "type": "band" }, "y": { "type": "linear", "zero": true } },
"guides": [
{ "type": "grid", "scale": "y" },
{ "type": "axis", "scale": "x" },
{ "type": "axis", "scale": "y", "format": "compact" }
],
"marks": [{ "type": "rect", "x": "region", "y": "total", "radius": 2 }],
"interaction": [{ "type": "tooltip" }]
}
</script></div>
<div class="demo theme-mono"><script type="application/json" data-bc-chart>
{
"data": "sales",
"size": [520, 220],
"scales": { "x": { "type": "band" }, "y": { "type": "linear", "zero": true } },
"guides": [
{ "type": "grid", "scale": "y" },
{ "type": "axis", "scale": "x" },
{ "type": "axis", "scale": "y", "format": "compact" }
],
"marks": [{ "type": "rect", "x": "region", "y": "total", "radius": 2 }],
"interaction": [{ "type": "tooltip" }]
}
</script></div>
<div class="demo theme-neon"><script type="application/json" data-bc-chart>
{
"data": "sales",
"size": [520, 220],
"scales": { "x": { "type": "band" }, "y": { "type": "linear", "zero": true } },
"guides": [
{ "type": "grid", "scale": "y" },
{ "type": "axis", "scale": "x" },
{ "type": "axis", "scale": "y", "format": "compact" }
],
"marks": [{ "type": "rect", "x": "region", "y": "total", "radius": 2 }],
"interaction": [{ "type": "tooltip" }]
}
</script></div>
</div> The variables
The first eight colors are for categories, in order of first appearance. Everything has a default, so you only set what you want to change.
CSS
.my-theme {
--bc-text: #5b3a1e; /* text in the chart and its tooltip */
--bc-label: #7a5634; /* quieter labels: ticks, legend (default: --bc-text) */
--bc-axis: #b08968; /* axis lines and ticks */
--bc-grid: #f0e2d0; /* grid lines */
--bc-tooltip-bg: #fff8ee; /* tooltip background */
--bc-c0: #c1440e; /* category colors, --bc-c0 ... --bc-c7 */
--bc-c1: #e29a3b;
--bc-c2: #7a4e2d;
--bc-brush-fill: rgba(43, 108, 176, .15); /* selection rectangle of the brush */
--bc-brush-line: #2b6cb0;
}
@media (prefers-color-scheme: dark) {
.my-theme { --bc-text: #d6d3d1; --bc-grid: #2a2826; /* ... */ }
}