Loading component…
Loading component…
The chart on its own for any card or layout – line, area, bars or a sparkline from the same data, with a tooltip and this period against the last
To reuse this local React demo, copy all files from the Code tab into the same folder, then import TrendChart from ./trend-chart.
import { TrendChart } from "@/components/ui/trend-chart";
export function Spend() {
return (
<TrendChart
variant="area"
label="Spend per day"
labels={["Mar 3", "Mar 4", "Mar 5", "Mar 6"]}
format={(n) => `$${Math.round(n)}`}
series={[
{ label: "This week", values: [412, 455, 398, 470] },
{ label: "Last week", values: [356, 380, 371, 390], previous: true },
]}
/>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| labels | string[] | One label per point; first, middle and last are shown on the axis | |
| tooltipLabels | string[] | Longer labels for the tooltip header, falls back to labels | |
| series | TrendSeries[] | { label, values, color?, previous? } – values line up with labels, null leaves a gap; previous draws it dashed (line) or faint (bar) | |
| variant | "line" \| "area" \| "bar" \| "sparkline" | "line" | How the same data is drawn – a sparkline has no axes and a small tag instead of the tooltip |
| format | (n: number) => string | compact, e.g. 1.2k | Formats tooltip values – and the axis, unless axisFormat is set |
| axisFormat | (n: number) => string | Shorter numbers for the axis, e.g. "$1.6T" while the tooltip shows the full amount | |
| height | number | 152 (sparkline 40) | Height of the plot in px |
| axis | boolean \| "x" | true (sparkline false) | Value labels on the left and dates below, only the dates ("x"), or none – without axes a small tag replaces the tooltip |
| tooltip | boolean | true | The popover or tag with the values – off when the card shows the value itself; the point stays marked |
| zero | boolean | true | Start the value axis at zero; false zooms in around the values for averages and rates (bars always start at zero) |
| index | number \| null | The highlighted point, controlled – share it between charts so they move together | |
| onIndexChange | (index: number \| null) => void | Called when the pointer or the keys move to another point, or leave | |
| defaultIndex | number | Point that stays highlighted while nobody hovers | |
| label | string | "Chart" | Name for screen readers |
| emptyText | string | "No data yet" | Quiet text in the plot when there are no values, or only zeros |
| fill | { opacity?; fade? } | Area only: how strong the fill under each line starts (0–1, default 0.2) and how far down it has faded to nothing (0–1 of the area, default 1) – lower both when several areas overlap, e.g. { opacity: 0.12, fade: 0.55 } | |
| className | string | Extra class on the chart |
Fills the width of its container; the plot scales, line widths stay crisp
Below 320px the middle date steps aside; below 240px tooltip values move under their names
Touch works too – tap or drag across the chart
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"