Design System
Widgets

Chart card

A titled card wrapping a chart, with a headline value and trend above it.

Purpose

A Stat card that carries a shape: title, headline value and trend pill, with a compact area chart underneath. Use it for dashboard KPIs where the trajectory matters as much as the number — claims volume, spend, utilisation over the last week. It composes Card with the Chart wrapper, so the series colour comes from the --chart-* palette, never from the component.

Use it for

  • A KPI with its recent trajectory: claims volume, spend, rejections
  • Compact single-series time windows (a week, a month)

Reach for something else

  • Number only, no shape → Stat card
  • Multi-series or analytical charts with legends and axes → Chart inside a plain Card

Example

Claims volume (7 days)

1,800

+8.4%

The wiring: dataKey names the numeric field, xKey the category field, and config — keyed by the same dataKey — supplies the series label (used by the tooltip) and its colour.

Claims volume card
import { ChartCard } from "@healthmetrics/ui/chart-card";

const claimsTrend = [
  { d: "Mon", v: 220 },
  { d: "Tue", v: 280 },
  { d: "Wed", v: 250 },
  { d: "Thu", v: 340 },
  { d: "Fri", v: 410 },
  { d: "Sat", v: 180 },
  { d: "Sun", v: 120 },
];

<ChartCard
  title="Claims volume (7 days)"
  value="1,800"
  trend={{ value: "+8.4%", direction: "up" }}
  data={claimsTrend}
  dataKey="v"
  xKey="d"
  config={{ v: { label: "Claims", color: "var(--chart-1)" } }}
/>;

Header variants

value and trend are both optional — omit them and the header collapses to the title alone. The trend pill's colour follows good, which defaults to true only when direction is "up"; for metrics where a fall is welcome (rejections, approval time), pass good: true on a downward trend explicitly.

Guarantee letters
A downward trend that is good news
<ChartCard
  title="Rejections (7 days)"
  value="142"
  trend={{ value: "-6.2%", direction: "down", good: true }}
  {/* … */}
/>

Structure

PropertyValue
ContainerCard surface, header/content padding
Title14px / Inter 500, --muted-foreground (text-sm font-medium)
Value24px / Inter 700 (text-2xl font-bold)
Trend pill14px / Inter 600, 18px arrow glyph; good --success-text, bad --destructive
Chart3:1 aspect area chart, 2px stroke, gradient fill 30% → 2% opacity
Axis/grid11px x-axis labels, horizontal grid lines only, no axis or tick lines
Colourvar(--color-<dataKey>), set from config via the Chart wrapper

Best practices

Do

  • Key config by the same string as dataKey — that key resolves the series colour and the tooltip label.
  • Take colours from the chart palette (var(--chart-1)…var(--chart-5)), not hex values.
  • Pre-format value — it renders verbatim, so pass "1,800", "MYR 48,200".
  • Keep the window short and the series single — this is a KPI tile, not an analysis view.
  • Pass good explicitly whenever a downward trend is welcome.

Don't

  • Plot multiple series or add legends — compose the Chart wrapper in a plain card instead.
  • Repeat the units on every axis label; put them in the title ("Spend (MYR, 7 days)").
  • Use it when nobody needs the shape — Stat card is lighter.

Accessibility & keyboard

  • The title and headline value are text — they, not the chart, must carry the takeaway. The chart is an SVG with no text alternative, and its values surface only in a hover tooltip.
  • The trend arrow is decorative (aria-hidden); keep the sign in trend.value ("+8.4%") so the direction survives as text.
  • Trend colour never stands alone — it is always paired with the signed value.
  • Keyboard: none — the card is not interactive and the tooltip is hover-only. If the underlying figures matter, provide them elsewhere (a Table or a linked report).

Props

ChartCard is a client component (recharts) — render it from a demo module or a client boundary, with plain serialisable props.

PropTypeDefaultDescription
titlerequiredstring—Card heading, e.g. "Claims volume (7 days)".
valueReact.ReactNode—Optional headline metric shown under the title.
trend{ value: string; direction: "up" | "down"; good?: boolean; } | undefined—Optional trend pill. `direction` sets the arrow; colour follows `good` (defaults to `true` when the direction is `up`).
datarequiredRecord<string, string | number>[]—Chart series data — one object per point.
dataKeyrequiredstring—Key in each datum holding the numeric series value (the area).
xKeyrequiredstring—Key in each datum holding the x-axis category label.
configrequiredChartConfig—Recharts/shadcn chart config keyed by series — supplies label and colour.
classNamestring | undefined——
ChartCard in Storybook

On this page