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

Sequential Scale

For heatmaps, choropleths, and other binned or intensity-based charts, use the sequential scale tokens (01 = lowest, 05 = highest):

CSS PropertyDescription
--chart-scale-01Empty / lowest intensity
--chart-scale-02Level 1
--chart-scale-03Level 2
--chart-scale-04Level 3
--chart-scale-05Highest intensity
--chart-scale-pattern-colorPattern stroke for zero / empty cells

Import typed references from @bklitui/ui/charts:

import { chartScaleCssVars, CHART_SCALE_VARS } from "@bklitui/ui/charts";

<ChoroplethFeatureComponent fill={chartScaleCssVars.scale03} />

Track & radial charts

Ring tracks, gauge inactive notches, and radar grid lines share the shadcn --border token:

CSS PropertyUsed by
--borderRing track background, gauge track notches, RadarGrid / RadarAxis strokes
import { ringCssVars, radarCssVars } from "@bklitui/ui/charts";

// ringCssVars.ringBackground → var(--border)
// radarCssVars.border → var(--border)

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);

  /* Sequential scale (heatmap / choropleth) */
  --chart-scale-01: oklch(0.98 0.003 106);
  --chart-scale-02: oklch(0.92 0.008 106);
  --chart-scale-03: oklch(0.82 0.015 106);
  --chart-scale-04: oklch(0.68 0.02 106);
  --chart-scale-05: oklch(0.55 0.025 106);
  --chart-scale-pattern-color: oklch(0.96 0.005 106);

  /* Ring / gauge / radar tracks */
  --border: oklch(0.92 0.004 286.32);
}

.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}
/>