Data

Chart

Recharts wrapper that consumes the theme --data-* palette.

Preview
01 Installation

Install

Pull Chart from the barrel for everyday use, or the granular path when you want a tighter bundle.

tsxBarrel1 line
import { Chart } from "@brika/clay";
tsxGranular1 line
import { Chart } from "@brika/clay/components/chart";
02 Usage

A minimal example

Drop this into a page. Native HTML attributes pass through to the underlying primitive.

tsxChart.tsx41 lines
import {
  type ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from '@brika/clay/components/chart';
import {
  Bar,
  BarChart,
  CartesianGrid,
  XAxis,
  YAxis,
} from 'recharts';
const monthLabels = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'] as const;

const compact = new Intl.NumberFormat('en-US', {
  notation: 'compact',
  maximumFractionDigits: 1,
});

/** Vertical bar chart with a single series, themed via `ChartContainer` config. */
export default function ChartBarDemo() {
  const data = monthLabels.map((month, i) => ({
    month,
    visitors: 1820 + i * 240 + (i % 2) * 180,
  }));
  const config: ChartConfig = {
    visitors: { label: 'Visitors', color: 'var(--data-1)' },
  };
  return (
    <ChartContainer config={config} className="h-72 w-full">
      <BarChart data={data} margin={{ top: 12, right: 12, left: 4, bottom: 0 }}>
        <CartesianGrid vertical={false} />
        <XAxis dataKey="month" tickLine={false} axisLine={false} />
        <YAxis tickLine={false} axisLine={false} width={40} tickFormatter={(v) => compact.format(v)} />
        <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
        <Bar dataKey="visitors" fill="var(--color-visitors)" radius={[6, 6, 0, 0]} />
      </BarChart>
    </ChartContainer>
  );
}
03 Examples

Chart, every way

Bar, Grouped

Two series rendered side-by-side, colour-keyed via the config palette.

Bar, Stacked

Stacked bar chart, bars share a column, totalled top-to-bottom.

Donut

Donut variant with a center label showing the running total.

KPI Dashboard

Sparklines compose into a KPI strip; each one keeps its own color via the data palette.

Labeled Axes

`xLabel`/`yLabel` add axis titles; tick formatters render dates and currency for a finance-style chart.

Line, Multi-series

Multi-series line chart with a dashed target overlay and a themed legend.

Live Stream

Live-streaming chart with controls, pick a metric, swap the time window, pause / resume the simulated feed.

Pie

Pie chart with a custom legend, segments map to the data palette via per-row `fill`.

Radar

Radar chart, multivariate comparison across labelled axes.

Radial

Radial bar chart, useful for goal-completion or capacity visualisations.

With Axes

`showAxes` reveals tick labels on both axes plus a faint grid; tooltip gets a timestamp header.

04 Accessibility

Accessibility

  • Charts are visual, provide a <caption> or adjacent text summary for screen readers.
  • Recharts renders an SVG; ensure the wrapper has role="img" and aria-label describing the data.
  • Tooltips visible on hover are not reliably announced by AT, critical data should also appear in text form.
05 Tokens 3 theme-overridable

Theme tokens

Every CSS variable Chart reads, with its default and the dotted path you'd write in a ThemeConfig JSON to override it. Set any of these in your theme to retune Chart without touching component code.

Chart tokens

3 tokens
ColorFill, border, and text colors.3
  • --chart-tooltip-containercolorvar(--popover)
    components.chart.tooltipContainer

    Background color of the chart tooltip surface. Defaults to the theme popover so tooltips read as floating UI.

  • --chart-tooltip-labelcolorvar(--popover-foreground)
    components.chart.tooltipLabel

    Text color of the chart tooltip readout. Defaults to the theme popover foreground.

  • --chart-tooltip-bordercolorvar(--border)
    components.chart.tooltipBorder

    Border color of the chart tooltip surface. Defaults to the theme border.

Override in a theme

Authoring a theme is plain JSON. Drop overrides under components.chart, the names are camelCase versions of the variable suffix.

jsonmy-theme.json12 lines
{
  "id": "my-theme",
  "name": "My Theme",
  "description": "...",
  "accentSwatches": ["#000"],

  "components": {
    "chart": {
      "tooltipContainer": "var(--popover)"
    }
  }
}

Then apply with applyTheme(myTheme) (see the theming guide), scope it to a subtree with themeToCssVars(myTheme, mode), or consume any token directly in your own JSX with the matching Tailwind utility (e.g. bg-chart-…) — see the chips on each token row.

06 API reference

API reference

Props specific to Chart. Native HTML attributes pass through to the underlying primitive, see the component source on GitHub for the full type signature.

Chart exposes no wrapper-specific props.

All props pass through to the underlying HTML / Radix primitive, see the component source linked above for the full type signature.