videorc/ui

Chart

shadcn's Recharts wrapper on Videorc's tokens. Series stay neutral unless their colour means something, and the tooltip floats on the popup glass.

Installation

$ pnpm dlx shadcn@latest add @videorc/chart

Usage

import { Area, AreaChart } from "recharts";

import {
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart";
import type { ChartConfig } from "@/components/ui/chart";
const config = {
  kbps: { color: "var(--foreground)", label: "Bitrate (kbps)" },
} satisfies ChartConfig;

<ChartContainer className="aspect-auto h-56" config={config}>
  <AreaChart data={data}>
    <ChartTooltip content={<ChartTooltipContent />} />
    <Area dataKey="kbps" fill="var(--color-kbps)" stroke="var(--color-kbps)" />
  </AreaChart>
</ChartContainer>;

Every key in the config becomes a --color-<key> variable on the chart, per theme. Point a mark's fill and stroke at it.

Anatomy

<ChartContainer config={config}>
  <AreaChart>
    <ChartTooltip content={<ChartTooltipContent />} />
    <ChartLegend content={<ChartLegendContent />} />
  </AreaChart>
</ChartContainer>

Examples

Sparklines

A stats sparkline has no axes, no tooltip and no animation: the number above it is the reading. It's neutral by default and takes the warning tone only when the tile itself is a warning, with an icon beside its label so the colour is never alone.

Bitrate6,012 kbps
Viewers214
Dropped frames2.4%

Bars

One neutral series with its value at the tip of each bar. The platform names on the axis carry identity, so the bars need no colour of their own.

Theming

The theme has no --chart-* palette. Videorc's chrome is monochrome and colour carries meaning, so a chart colours its series from the tokens it already has:

ColourWhen
var(--foreground), var(--muted-foreground)Every series, by default
var(--warning)A reading that needs attention
var(--destructive)A failure
glass-floatThe tooltip: the popup glass with its rim and drop
rounded-rowThe tooltip's 8 px radius
stroke-border, fill-muted-foregroundGrid lines, reference lines and axis text

Give a series a theme instead of a color when it needs a different value in light and dark.

Accessibility

Recharts' accessibilityLayer (on by default) lets the keyboard move through a chart's points and opens the tooltip on each. A chart is never the only place its numbers live: say the current reading in words beside it, and mark a decorative sparkline aria-hidden.

API reference

ChartContainer

Every div prop, plus:

Prop

Type

ChartTooltipContent

Every Recharts Tooltip content prop, plus:

Prop

Type

ChartLegendContent

Prop

Type

ChartTooltip and ChartLegend are Recharts' Tooltip and Legend.