本文へ移動
日本語
「ゲージチャート」は Pro に含まれます。解除するとプレビューが表示されます。

仕組み

Both arcs are the same half circle with pathLength="1": the value arc runs left to right, the rest arc right to left, and each shows its part through stroke-dashoffset alone. A 6px gap separates them between the round caps. One CSS transition carries the entrance and every later change, so a new value moves from the old one and never sweeps back through zero. The centre number, the legend values and their shares count on the same curve.

向いている場面

  • One amount against a known whole: budget spent, a weekly goal, beds or seats in use.
  • A card where the split between used and left matters as much as the number itself.

向かない場面

  • More than two parts: use the donut chart.
  • Values without a natural maximum, such as visits: use a bar chart or a stat card.
  • Change over time: use a line or bar chart.

使い方

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

export function BudgetCard() {
  return (
    <GaugeChart
      title="Monthly budget"
      qualifier="November"
      value={1846}
      max={2600}
      center={2600}
      caption="Budget"
      valueLabel="Spent"
      restLabel="Left"
      formatValue={(n) => `$${n.toLocaleString('en-US')}`}
      footnote={<><b>Eating out is under plan</b>Groceries went $64 over.</>}
    />
  )
}

プロパティ

プロパティ型既定値説明
title / qualifierstring—Card title (15px semibold) and grey words after it.
iconReactNode—An 18px icon in a 32px square tinted with the card colour.
onAction / actionIcon / actionLabel / action() => void / 'open' | 'more' / string / ReactNode- / 'open'A round chevron or three-dot button at the right of the title row, its accessible name, or your own element instead.
valuenumber—The measured amount; clamped to 0…max. The coloured arc shows value / max.
maxnumber100The whole. The neutral arc and the second legend row show max − value.
centernumber—Number in the centre. Defaults to value; pass max to show the whole, such as the budget.
captionstring—Grey line above the centre number.
unitstring—Unit beside the centre number, such as h or kg.
valueLabel / restLabelstringtext.value / text.restNames of the two legend rows, such as Spent and Left.
footnoteReactNode—Text under a hairline at the bottom; a leading <b> reads as its heading.
tone1-81Which --ds-chart-N colour the arc uses.
sizenumber196Width of the half ring in px (120-320); the height follows.
thicknessnumber16Arc width in px.
formatValue(n) => stringn.toLocaleString('en-US')Formats the centre and legend numbers; while counting it receives in-between values rounded to the target's decimals.
formatPercent(p) => string`${Math.round(p)}%`Formats the legend shares (0-100).
textobject—Replaces built-in words (value, rest, open, more, meter); shallow-merged over the English defaults.
labelstring—Accessible name of the meter; defaults to the title.
replayKeyany—Change it to play the sweep again from zero.
...restHTMLAttributes<HTMLDivElement>—Other attributes go to the card.

アクセシビリティ

  • The dial is role="meter" with aria-valuenow, min and max, and a valuetext that reads the value, the whole and the share.
  • The legend repeats both numbers and shares as text, so colour is never the only cue.
  • Hovering an arc or a legend row softens the other part; nothing is shown only on hover.
  • With reduced motion the arcs and numbers appear in their final state at once.

モーション

When 30% of the card is on screen the value arc sweeps from the left over 900ms on cubic-bezier(0.22, 1, 0.36, 1) while the rest arc shrinks from full; the centre number counts up and the legend counts the value up and the rest down on the same curve. Later changes take the same path from the current value; hover softening takes 160ms.

プロジェクトに追加

Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。

GaugeChart.jsxgauge-chart.csstokens.cssREADME.md

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

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