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)
Example
1,800
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.
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.
<ChartCard
title="Rejections (7 days)"
value="142"
trend={{ value: "-6.2%", direction: "down", good: true }}
{/* … */}
/>Structure
| Property | Value |
|---|---|
| Container | Card surface, header/content padding |
| Title | 14px / Inter 500, --muted-foreground (text-sm font-medium) |
| Value | 24px / Inter 700 (text-2xl font-bold) |
| Trend pill | 14px / Inter 600, 18px arrow glyph; good --success-text, bad --destructive |
| Chart | 3:1 aspect area chart, 2px stroke, gradient fill 30% → 2% opacity |
| Axis/grid | 11px x-axis labels, horizontal grid lines only, no axis or tick lines |
| Colour | var(--color-<dataKey>), set from config via the Chart wrapper |
Best practices
Do
- Key
configby the same string asdataKey— 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
goodexplicitly whenever a downward trend is welcome.
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 intrend.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.
| Prop | Type | Default | Description |
|---|---|---|---|
titlerequired | string | — | Card heading, e.g. "Claims volume (7 days)". |
value | React.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`). |
datarequired | Record<string, string | number>[] | — | Chart series data — one object per point. |
dataKeyrequired | string | — | Key in each datum holding the numeric series value (the area). |
xKeyrequired | string | — | Key in each datum holding the x-axis category label. |
configrequired | ChartConfig | — | Recharts/shadcn chart config keyed by series — supplies label and colour. |
className | string | undefined | — | — |