本文へ移動
日本語

仕組み

The plot measures its own width with a ResizeObserver and draws the SVG at that size, so 12px ticks and round points never scale. Ticks are round numbers (1, 2, 2.5 or 5 times a power of ten) starting at zero. Points are a slightly lightened series colour with a ring in the surface colour, so dense clusters keep their edges, and they pop in on a spring with a small stagger. Pointing finds the nearest point within 28px: it grows, the other series fade, dashed guides run to both axes and a dark tooltip follows, flipping below near the top. The legend buttons toggle series, always leaving at least one.

向いている場面

  • Showing whether two measures move together, and how groups differ: time against pages, price against rating, size against duration.

向かない場面

  • Thousands of points: draw them on a canvas or bin them into a heatmap.
  • Values over time: use a line chart.

使い方

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

export function Engagement({ desktop, mobile }) {
  return (
    <ScatterChart
      title="Engagement by device"
      label="Minutes on site against pages viewed, by device"
      xLabel="Minutes on site"
      yLabel="Pages"
      series={[
        { name: 'Desktop', data: desktop },
        { name: 'Mobile', tone: 3, data: mobile },
      ]}
      trend
    />
  )
}

プロパティ

プロパティ型既定値説明
series{ name: string, data: { x: number, y: number, label?: string }[], tone?: 1-8, color?: string }[]—Series in legend order; colours default to --ds-chart-1, 2, 3… A point's label heads its tooltip.
title / subtitleReactNode—Heading above the legend.
xLabel / yLabel / formatX / formatYstring / (v) => string—Axis names (shown under the plot and in the tooltip) and tick formatting.
heightnumber260Plot height in px; the width follows the container.
pointSize / trend / gridnumber / boolean / boolean4.5 / false / truePoint radius, a least-squares line per series, dashed horizontal grid lines.
label / labelsstring / { show(name), hide(name), point(series, point) }—Accessible name of the chart, legend button names and the sentence announced for a point.

アクセシビリティ

  • The chart is an image with an accessible name; describe the takeaway in label.
  • It is focusable: arrow keys step through points from left to right, Home and End jump, Escape clears, and each point is announced in a polite live region.
  • Legend buttons are toggle buttons with aria-pressed and a “Show/Hide name” label; the hidden state also changes the swatch to an outline, so it is not colour alone.
  • Reduced motion removes the pop-in, the trend draw and the tooltip glide.

モーション

Points: 460ms spring pop with a 22ms stagger. Trend: 900ms draw from 300ms. Focus: 220ms spring grow; tooltip glides 200ms.

プロジェクトに追加

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

ScatterChart.jsxscatter-chart.csstokens.cssREADME.md

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

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