Theming
Colors, slots, shading and dark mode.
Customization climbs a ladder. Behaviour is a prop: the keys and gestures (keymap), the renderer, the durations, and what shows (legend, shortcuts, gizmo) - see chart-3d. Looks are CSS: the theme tokens below and the slots, never style props. Identity is fixed: how hover highlights, how the gestures are gated and that every renderer draws the same scene are decisions, recorded in the ADRs - to change those, edit your copy of the registry file: you own it.
The config
ChartContainer3D takes a ChartConfig: one entry per series, with a label and a color. It has the same shape as the config of the shadcn/ui chart, so you can share one between a 2D and a 3D chart.
const chartConfig = {
desktop: { label: "Desktop", color: "var(--chart-1)" },
mobile: {
label: "Mobile",
theme: { light: "oklch(0.6 0.118 184.704)", dark: "oklch(0.696 0.17 162.48)" },
},
} satisfies ChartConfigThe container turns every key into a CSS variable, --color-desktop and --color-mobile, scoped to the chart; a ChartLegend3D placed on its own scopes them itself. A key may hold any text: a character a CSS identifier cannot hold, such as the space of Net sales, is escaped, and a chart of your own reads the variable of a key with colorOf(key). color is used in both themes, theme sets one color per theme.
The container writes its id, the keys and the colors into a <style> element, and a legend on its own its keys and colors. Both keep them from closing it but do not check that they are CSS: validate any of them that comes from your users.
The chart tokens
A chart draws in the colors its config names: above, --chart-1, a token of your shadcn/ui theme. Change it in your global CSS and every chart that names it follows; a key without a color draws in the color of the text. The walls of the chart box and its gridlines use --muted and --border, the lines of the axes, their tick marks and their titles --foreground, the tick labels and the gizmo --muted-foreground, the tooltip --background and --foreground. The ocean and the land of the globe draw in --chart-3d-ocean and --chart-3d-land where you set them, and otherwise in --muted and --border; set them on the chart, or any ancestor, for a globe at night:
.globe {
--chart-3d-ocean: oklch(0.22 0.02 260);
--chart-3d-land: oklch(0.36 0.02 260);
}The focus color
Pointing at a mark lights the fill of its element - the hover highlight. It takes --chart-3d-focus where you set it, and otherwise the mark's own fill, lightened with color-mix, so the highlight carries the color of what it highlights; a stroke of the mark's own, such as the ring of a scatter point, stays. The core resolves it for every renderer; set the property on the chart, or any ancestor, for one color instead:
[data-slot="chart-3d"] {
--chart-3d-focus: var(--ring);
}Slots
Every visible part of a chart carries a data-slot, the public hook for your
stylesheet: restyle it, move it, hide it, without touching the component.
| Slot | The part |
|---|---|
chart-3d | the container, which also takes className |
chart-3d-canvas | the canvas of the canvas renderer |
chart-3d-marks | the marks, as SVG |
chart-3d-axes | the box: walls, gridlines, axis lines, ticks |
chart-3d-labels | the labels beside the marks |
chart-3d-tooltip | the tooltip (placement sets its corner, data-placement names the one it took) |
chart-3d-hint | the veil of the hint of a drag that missed (data-state is "open" or "closed") |
chart-3d-hint-box | the box of the hint, in the middle of the veil |
chart-3d-legend | the legend, below the chart or on its own |
chart-3d-gizmo | the orientation gizmo (a gizmo prop sets its corner) |
chart-3d-shortcuts | the corner that holds the keyboard button and its panel |
chart-3d-shortcuts-trigger | the keyboard button (a shortcuts prop hides it) |
chart-3d-shortcuts-panel | the shortcut panel |
chart-3d-shortcuts-label | the label naming each row of the panel |
chart-3d-shortcuts-rule | the rule between the keys of a row and its gestures |
kbd-group, kbd | the key groups and keys inside the panel |
For example, to move the keyboard button and its panel into the upper left corner - the lower one holds the gizmo:
[data-slot="chart-3d-shortcuts"] {
right: auto;
left: 0.5rem;
align-items: flex-start;
}The keyboard button ships clickable the way a shadcn/ui ghost button does - the pointer cursor, and on hover the full --background behind it, where it is see-through at rest, and its icon in --accent-foreground. To add a little lift on top:
[data-slot="chart-3d-shortcuts-trigger"] {
transition: transform 150ms;
}
[data-slot="chart-3d-shortcuts-trigger"]:hover {
transform: scale(1.15);
}The scene fades out at the edges of its box, through a CSS mask on the svg and the canvas. Plain CSS takes it off - or restyles it with your own mask-image:
[data-slot="chart-3d"] svg,
[data-slot="chart-3d-canvas"] {
mask-image: none;
}The stylesheet is one of three doors, and all of them are the shadcn way. A single utility reads best as className on the container, with the slot as an arbitrary variant:
<ChartContainer3D
config={config}
className="[&_[data-slot=chart-3d-shortcuts-trigger]]:rounded-full"
/>And since you own your copy of chart-3d.tsx, a change that should hold in every chart of your app can go straight onto the button's own classes. The stylesheet door stays open for the other two kinds of users: a project without Tailwind, and the npm package, which has no copy to edit.
Shading
A face of a bar or a surface gets lighter or darker by how much it faces a light from the upper left:
color-mix(in oklch, var(--color-desktop) 80%, black)The shade is CSS, not a color computed in JavaScript, so it follows a theme switch without a re-render, and any color you set in the config works, including var() references.
Dark mode
The dark colors apply under a .dark class on an ancestor, the convention of shadcn/ui and next-themes.