Usage
import { DashboardChart } from './DashboardChart.jsx'
// Without data the card shows its sample bakery. Wire it to your numbers (money with a currency;
// format="number" | "percent" | "duration" | (v) => string for anything else):
<DashboardChart
locale="en"
format="duration"
labels={{ title: 'Brew time' }}
ranges={[{ id: 'week', label: 'Week', compare: 'vs the day before' }]}
data={{ week: { categories: days, series: [{ id: 'filter', name: 'Filter', data: filterSeconds }, { id: 'espresso', name: 'Espresso', data: espressoSeconds }] } }}
onRangeChange={async (range) => await fetchSales(range)}
onSeriesToggle={(id, shown) => remember(id, shown)}
loading={sales.loading}
error={sales.error}
onRetry={sales.reload}
/>Props
| Prop | Type | Default | What it does |
|---|---|---|---|
locale | 'en' | 'zh-CN' | 'es' | 'ja' | 'en' | Language of the built-in text, the sample sales and the number formats. |
ranges | Array<{ id, label, compare, caption? }> | week, month, year | The periods of the switch: tab label, what the change compares with, and how a column is named above the total. |
data | { [rangeId]: { categories: string[], names?: string[], series: Array<{ id, name, data, color? }> } } | sample bakery | The columns (`categories`, short; `names`, in full for above the total; `labels` is the older name of `categories`) and up to two series of each period. A period without data shows the empty state. |
range / defaultRange | string | 'week' | The period shown, controlled or at first. |
format | 'currency' | 'number' | 'percent' | 'duration' | (value) => string | 'currency' for the sample or with `currency`, else 'number' | How the total and the chips read: money, a number with the data’s decimals, a percent (42 reads 42 %), a duration in seconds, or your function. |
currency | string | by locale | ISO currency code of every amount. |
onRangeChange | (range) => void | Promise<{ labels, series }> | — | The period changed. Resolve with the data of a period missing from data; the chart dims meanwhile. |
onSeriesToggle | (id, shown) => void | — | A series was shown or hidden. The last one shown cannot be hidden. |
onSelect | (index) => void | — | A column was chosen by click, tap or arrow keys. |
loading | boolean | false | Shows the skeleton of the card. |
error / onRetry | boolean | string / () => void | false | Shows the error banner with a retry button; a string replaces its sentence. |
labels | object | — | Replaces any built-in text (keys as in copy.js). |
Add it to your project
Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the block together with the components it is built from.
DashboardChart.jsxdashboard-chart.csscopy.jskit.jsxkit.cssui/base-button/ui/area-chart/ui/empty-state/ui/alert-banner/ui/skeleton-shimmer/ui/sliding-tabs/tokens.cssREADME.md
The block, its stylesheet and text, the shared kit, the components it uses and tokens.css install together into one folder.