Theming

Theme your charts using CSS custom properties for consistent, customizable styling.

Charts use CSS custom properties (variables) for theming, allowing you to customize colors across light and dark modes without modifying component code.

Using chartCssVars

The chartCssVars object provides type-safe access to chart CSS variables:

import { chartCssVars } from "@bklitui/ui/charts";

// In your component
<rect fill={chartCssVars.indicatorColor} />
<line stroke={chartCssVars.crosshair} />

This is preferred over hardcoding CSS variable strings, as it provides autocomplete and prevents typos.

Available Variables

Core Colors

VariableCSS PropertyDescription
background--chart-backgroundChart container background
foreground--chart-foregroundPrimary text/element color
foregroundMuted--chart-foreground-mutedSecondary/muted text color
label--chart-labelAxis label text color

Line & Grid

VariableCSS PropertyDescription
linePrimary--chart-line-primaryPrimary line stroke color
lineSecondary--chart-line-secondarySecondary line stroke color
crosshair--chart-crosshairTooltip crosshair line color
grid--chart-gridGrid line color

Indicators

VariableCSS PropertyDescription
indicatorColor--chart-indicator-colorPrimary indicator color (e.g., hover lines)
indicatorSecondaryColor--chart-indicator-secondary-colorSecondary indicator color

Markers

VariableCSS PropertyDescription
markerBackground--chart-marker-backgroundMarker circle background
markerBorder--chart-marker-borderMarker circle border
markerForeground--chart-marker-foregroundMarker icon color
badgeBackground--chart-marker-badge-backgroundMarker count badge background
badgeForeground--chart-marker-badge-foregroundMarker count badge text

Data Series Colors

These are used for coloring different data series in multi-line charts:

CSS PropertyDescription
--chart-1First series color
--chart-2Second series color
--chart-3Third series color
--chart-4Fourth series color
--chart-5Fifth series color

Customizing Variables

Override CSS variables in your stylesheet to customize chart appearance:

:root {
  /* Light mode */
  --chart-background: oklch(1 0 0);
  --chart-foreground: oklch(0.145 0.004 285);
  --chart-grid: oklch(0.9 0 0);
  --chart-crosshair: oklch(0.4 0.18 274);
  --chart-indicator-color: oklch(0.21 0.006 285);
  
  /* Series colors */
  --chart-1: oklch(0.32 0 none);
  --chart-2: oklch(0.41 0 none);
  --chart-3: oklch(0.54 0 none);
}

.dark {
  /* Dark mode overrides */
  --chart-background: oklch(0.145 0 0);
  --chart-foreground: oklch(0.45 0 0);
  --chart-grid: oklch(0.25 0 0);
  --chart-indicator-color: oklch(1 0 0);
}

Example: Custom Indicator Theming

The Custom Indicator pattern uses --chart-indicator-color:

<motion.rect
  fill="var(--chart-indicator-color)"
  height={2}
  width={barWidth}
  x={barX}
/>

Or using the typed object:

import { chartCssVars } from "@bklitui/ui/charts";

<motion.rect
  fill={chartCssVars.indicatorColor}
  height={2}
  width={barWidth}
  x={barX}
/>