本文へ移動
日本語

仕組み

An inline SVG drawn at its exact pixel size, so the dot stays round and the stroke stays crisp. The curve is a monotone cubic: it passes through every point and never bulges past a peak or a dip, which a plain smoothing would. The line draws in with stroke-dashoffset on a normalised path length, the area fades in after it, and the last-value dot appears with a halo that swells once and settles. Pointing anywhere over it moves the dot to the nearest point on a spring and reports it through onActiveChange, so a table cell can show that day's value next to it.

向いている場面

  • Trends beside a number in a table, a list or a KPI card, where shape matters more than exact values.

向かない場面

  • When people need axes, units or comparisons between series: use a line chart.

使い方

import { Sparkline } from './Sparkline.jsx'

export function VisitorsCell({ history }) {
  return (
    <Sparkline
      data={history}
      width={96}
      height={28}
      variant="area"
      tone={1}
      label={`Visitors from ${history[0]} to ${history.at(-1)} over 14 days`}
      formatValue={(n) => n.toLocaleString('en-US')}
    />
  )
}

プロパティ

プロパティ型既定値説明
datanumber[] | { value: number }[]—Values in time order. Non-numbers are skipped.
width / heightnumber96 / 28Size in px; the chart draws at exactly this size so dots stay round.
variant'line' | 'area''line'A line alone, or with a gradient fill that fades out at the bottom.
tone / color1-8 / string1--ds-chart-N, or any colour.
smoothbooleantrueA monotone curve that passes through every point without overshooting; false draws straight segments.
dot / baselineboolean / numbertrue / -The last-value dot, and an optional dashed reference line at a value.
tooltip / formatValue / onActiveChangeboolean / (v) => string / (index, value) => voidtrueA value tag while pointing; or turn it off and show the value yourself with onActiveChange.
labelstring—Accessible name. By default it states the first, last, lowest and highest values.

アクセシビリティ

  • The chart is one image with a text summary (first, last, low and high by default); pass label for a sentence in your own words.
  • The SVG itself is hidden from assistive technology; the value tag is decorative.
  • Keep the number next to it in text, as the demo does: the chart is a supplement, not the only carrier of the value.
  • Reduced motion removes the draw, the halo pulse and the dot slide.

モーション

Line: 900ms draw on the reveal curve. Area: 700ms fade from 300ms. Dot: appears at 760ms; halo swells and settles over 1200ms. Pointing: 260ms spring slide.

プロジェクトに追加

プロンプトを Codex または Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込む内容を示したうえで、既存のコンポーネントの隣に追加します。

Sparkline.jsxsparkline.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

グラフ
「三辺測位」は Pro に含まれます。解除するとプレビューが表示されます。