# Scatter chart

Points on two value axes, for seeing a relation and outliers.

- Family: charts
- Import: `import { ScatterChart } from "@senvenli/react/charts";`
- Page: https://design.senvenli.com/docs/components/scatter-chart
- JSON: https://design.senvenli.com/docs/components/scatter-chart.json

## Example: Price and units sold

One point per product on two value axes.

```tsx
import { ScatterChart } from "@senvenli/react/charts";

const PRODUCTS = [
  { sku: "Desk mat", price: 29, units: 940 },
  { sku: "Cable tray", price: 38, units: 720 },
  { sku: "Footrest", price: 54, units: 610 },
  { sku: "Desk lamp", price: 79, units: 480 },
  { sku: "Monitor arm", price: 129, units: 390 },
  { sku: "Ergonomic chair", price: 349, units: 210 },
  { sku: "Standing desk", price: 589, units: 96 },
];
const usd = new Intl.NumberFormat("en", { style: "currency", currency: "USD", maximumFractionDigits: 0 });

export default function Example() {
  return (
    <ScatterChart
      title="Price and units sold"
      period="Q1 2026"
      data={PRODUCTS}
      name="sku"
      x="price"
      y="units"
      xLabel="Price (USD)"
      yLabel="Units sold"
      valueFormatters={{ x: usd.format }}
    />
  );
}
```

## Examples

### A second category and a size

The second group differs by shape as well as color; a third measure sets the point's size.

```tsx
import { ScatterChart } from "@senvenli/react/charts";

const CUSTOMERS = [
  { name: "Acme Corp", orders: 42, average: 310, revenue: 13020, plan: "enterprise" },
  { name: "Globex", orders: 18, average: 640, revenue: 11520, plan: "enterprise" },
  { name: "Initech", orders: 64, average: 95, revenue: 6080, plan: "team" },
  { name: "Umbrella", orders: 27, average: 180, revenue: 4860, plan: "team" },
  { name: "Hooli", orders: 9, average: 420, revenue: 3780, plan: "enterprise" },
  { name: "Stark Industries", orders: 51, average: 60, revenue: 3060, plan: "team" },
  { name: "Wayne Enterprises", orders: 33, average: 75, revenue: 2475, plan: "team" },
];
const usd = new Intl.NumberFormat("en", { style: "currency", currency: "USD", maximumFractionDigits: 0 });

export default function Example() {
  return (
    <ScatterChart
      title="Customers by order pattern"
      period="2026"
      data={CUSTOMERS}
      name="name"
      x="orders"
      y="average"
      size="revenue"
      category={{ key: "plan", value: "enterprise", label: "Enterprise", otherLabel: "Team" }}
      xLabel="Orders"
      yLabel="Order value (USD)"
      valueFormatters={{ y: usd.format }}
    />
  );
}
```

### With a trend line

A least-squares line shows the direction of the relation.

```tsx
import { ScatterChart } from "@senvenli/react/charts";

const CAMPAIGNS = [
  { campaign: "Spring sale", spend: 1200, revenue: 5400 },
  { campaign: "Newsletter", spend: 300, revenue: 2100 },
  { campaign: "Search ads", spend: 2600, revenue: 9800 },
  { campaign: "Social video", spend: 1800, revenue: 5900 },
  { campaign: "Partner webinar", spend: 900, revenue: 4700 },
  { campaign: "Retargeting", spend: 2100, revenue: 8900 },
  { campaign: "Podcast", spend: 3400, revenue: 10200 },
];
const usd = new Intl.NumberFormat("en", { style: "currency", currency: "USD", notation: "compact" });

export default function Example() {
  return (
    <ScatterChart
      title="Ad spend and revenue"
      period="Q1 2026 campaigns"
      data={CAMPAIGNS}
      name="campaign"
      x="spend"
      y="revenue"
      xLabel="Spend (USD)"
      yLabel="Revenue (USD)"
      valueFormatters={{ x: usd.format, y: usd.format }}
      trendLine
    />
  );
}
```

## Guidelines

### When to use it

- How two measures of the same items relate.

### Use something else when

- [line-chart](https://design.senvenli.com/docs/components/line-chart.md): One axis is time.
- [bar-chart](https://design.senvenli.com/docs/components/bar-chart.md): One axis is a category.

## Accessibility

Keyboard:

- Arrow keys: Move between points.

Built in:

- A "Show as table" button shows the same data as a table, which screen readers get by default.

You provide:

- A title that says what the figure is.

## API reference

### ScatterChart

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| title | `string` |  | no | What the chart shows, over it; leave it out when a card or a heading already says so. |
| aria-label | `string` |  | no | Names the chart when it has no visible `title` (a card's heading already says what it shows). |
| period | `string` |  | no |  |
| isLoading | `boolean` |  | no |  |
| emptyState | `React.ReactNode` |  | no | Shown instead of the plot when there is no data: an `EmptyState size="small"` or text; "No data" by default. |
| height | `number` |  | no |  |
| data | `readonly T[]` |  | yes |  |
| name | `keyof T & string` |  | yes | The key naming each point (a product's SKU); shown on hover and as the table's row header. |
| x | `keyof T & string` |  | yes |  |
| y | `keyof T & string` |  | yes |  |
| size | `keyof T & string` |  | no | A third measure as point size. |
| category | `{ key: keyof T & string; value: unknown; label: string; otherLabel: string; }` |  | no | A second category: `ds-chart-2` and a diamond, so it differs by shape as well as hue. |
| xLabel | `string` |  | yes | Axis names with their units ("Daily price (€)"). |
| yLabel | `string` |  | yes |  |
| valueFormatters | `{ x?: ChartValueFormatter \| undefined; y?: ChartValueFormatter \| undefined; }` |  | no |  |
| trendLine | `boolean` |  | no | A least-squares trend line, dashed in `ds-chart-neutral`. |
| onPointPress | `(row: T) => void` |  | no | Opens the item: the row under the pointer. |

### Tokens it reads

`--ds-background-neutral`, `--ds-background-neutral-pressed`, `--ds-border`, `--ds-border-bold`, `--ds-border-focused`, `--ds-chart-1`, `--ds-chart-2`, `--ds-chart-3`, `--ds-chart-4`, `--ds-chart-5`, `--ds-chart-neutral`, `--ds-link`, `--ds-radius-medium`, `--ds-radius-small`, `--ds-radius-xsmall`, `--ds-shadow-overlay`, `--ds-space-050`, `--ds-space-075`, `--ds-space-100`, `--ds-space-150`, `--ds-space-200`, `--ds-space-300`, `--ds-space-400`, `--ds-surface-overlay`, `--ds-surface-raised`, `--ds-text`, `--ds-text-danger`, `--ds-text-subtle`, `--ds-text-subtlest`, `--ds-text-success`

## Related

- [bar-chart](https://design.senvenli.com/docs/components/bar-chart.md)
