仕組み
The line chart card with a filled gradient under each line that is not muted. The area is its own SVG path closed to the baseline; on entry it scales up from the bottom (transform only) while the line above it draws with dashoffset. With a muted comparison series the gradient stays on the lead line only, so the comparison never competes. New data morphs both paths through the CSS d property where supported.
向いている場面
- A running total or balance where the filled area helps read volume: savings, storage used, subscribers.
- This year against last year, with last year as a quiet dotted line.
- A dashboard tile where one card should feel calmer and heavier than a bare line.
向かない場面
- More than two series: overlapping areas turn muddy; use the line chart.
- Values that go negative or swing around zero: areas imply a quantity from the baseline.
- Parts of a whole over time: use stacked bars.
使い方
import { AreaChart } from './AreaChart.jsx'
const months = ['Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov']
export function SavingsCard() {
return (
<AreaChart
title="Savings"
subtitle="last 6 months"
onOpen={() => {}}
caption={(month) => `Balance in ${month}`}
delta={{ value: 1240, label: 'vs last year' }}
categories={months}
series={[
{ name: 'This year', data: [13200, 14050, 14900, 15880, 17150, 18420] },
{ name: 'Last year', data: [10900, 11400, 12010, 12650, 13240, 13860], muted: true },
]}
formatValue={(n) => '$' + n.toLocaleString('en-US')}
color={3}
/>
)
}プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
categories | string[] | — | X-axis categories, usually dates or week numbers. One column and one point per label. `labels` is the older name of this prop and still works (deprecated: in blocks `labels` means text overrides). |
series | { name: string, data: (number | null)[], color?: number | string, muted?: boolean }[] | — | Up to 2 lines. The first one that is not muted leads: it sets the hero, the band and the tooltip colour. muted draws a dotted grey comparison line (last year, a plan) with no points and no area. color is 1–8 for --ds-chart-N or any CSS colour; null breaks the line. |
title / subtitle / icon | ReactNode | — | Card header: a tinted icon tile, a 15px title and a quieter subtitle after it. |
onOpen / action | () => void / ReactNode | — | onOpen adds a chevron button at the end of the header. action replaces it with any node, such as a menu. |
caption | string | (category: string, index: number) => string | — | Small line above the hero. A function receives the selected column, so the caption follows the selection. |
value | number | string | — | Hero value. If omitted it is the lead series at the selected column. Numbers count from the old value to the new one. |
unit | string | — | Unit after the hero and inside the tooltip, such as kg or %. |
delta | { value: number, label?: string, positive?: 'up' | 'down', format?: (n) => string } | — | Change badge after the hero. positive: 'down' makes a fall green, for weight or cost. |
reference | { value: number, label?: string } | — | A thin reference line with its value and label at the left, such as a goal. The y range always includes it. |
selected / onSelect | number / (index: number) => void | — | The column at rest, with the band, the big point and the ink axis pill. Defaults to the latest point; a click or Enter pins another one. |
color | number | string | 1 | Lead colour: 1–8 for --ds-chart-N with its soft partner, or a CSS colour. Further series take the next palette slots. |
height | number | 120 | Plot height in px, not counting the axis labels under it. |
smooth | boolean | true | Monotone curve that never overshoots into false peaks; false draws straight segments. |
yMin / yMax | number | — | Y range. By default it hugs the data with a little headroom, so small changes stay visible. |
format | 'number' | 'percent' | 'currency' | 'duration' | (n) => string | — | How values read: a number with the data's decimals, a percent (42 reads 42%), money in `currency`, a duration in seconds (4m 30s), or your function. Without it numbers keep up to two decimals. |
locale / currency | string / string | 'en-US' / 'USD' | Language of the number format and the ISO code used by format='currency'. |
formatValue | (n: number) => string | (n) => n.toLocaleString('en-US') | Your own number format for the hero, tooltip, reference label, legend and screen-reader table, ahead of `format`. |
showLegend | boolean | true | With two or more series, a legend whose values follow the selected or hovered column. |
label | string | — | Accessible name of the plot and caption of the hidden data table. Defaults to the title. |
text | object | — | Replaces built-in text: open, tip(value, unit), plot(name, count), point(category, parts), noData, category. Named text because labels holds the categories. |
replayKey | string | number | — | Change it to play the entrance again. Changing the categories also replays it; changing only values glides. |
className / style / ...rest | HTMLAttributes | — | Passed to the card root, which fills its container width. |
アクセシビリティ
- The plot is a focusable group named after the chart. Left and Right move between points, Home and End jump to the ends, Enter pins the column, Escape goes back to the pinned one.
- Each move is announced through a polite live region; a visually hidden table holds every value.
- The drawing is hidden from screen readers; the hero, delta and legend are real text.
- The muted series is told apart by its dotted stroke and legend name, not only by colour.
- Reduced motion shows the final chart at once and the numbers do not count.
モーション
Entrance waits until 30% of the card is visible. Over 900ms on cubic-bezier(0.22, 1, 0.36, 1) the line draws while its area rises from the baseline and the hero counts; points pop (420ms spring) as the line reaches them; the band rises at 520ms and the ink axis pill pops at 640ms. Hover moves the band and tooltip in 240ms; new data glides over 900ms.
プロジェクトに追加
プロンプトを Codex または Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込む内容を示したうえで、既存のコンポーネントの隣に追加します。
AreaChart.jsxarea-chart.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

