# ScatterChart

> How two measures relate, one dot per item. Add size for a bubble chart and groupBy for colored groups.

Status: beta. Category: Data display.

```ts
import { ScatterChart } from '@glyphui/ui/chart'
```

Exports: `ScatterChart`.

## Notes

- Always name both axes with xAxis.label and yAxis.label: a scatter has no other labels.
- Click a legend entry to hide a group. Set name to show each point’s name in the tooltip.

## ScatterChart props

| Prop | Type | Default | Description |
|---|---|---|---|
| `data` (required) | `readonly T[]` |  |  |
| `title` (required) | `string` |  |  |
| `x` (required) | `string` |  | Field for the horizontal position. |
| `y` (required) | `string` |  | Field for the vertical position. |
| `className` | `string` |  |  |
| `colors` | `readonly ChartColorValue[]` |  | One color per group, in order. |
| `description` | `ReactNode` |  |  |
| `empty` | `ReactNode` |  | Shown when there is no data. Defaults to a short "No data" message. |
| `error` | `unknown` |  | Shows an error message in place of the plot, with a retry button when `onRetry` is set. |
| `groupBy` | `string` |  | Field that splits points into colored groups with a legend. |
| `height` | `number` |  | Plot height in pixels. Default 280. |
| `hiddenGroups` | `readonly string[]` |  |  |
| `hideTitle` | `boolean` |  |  |
| `loading` | `boolean` |  | Shows a skeleton in place of the plot. |
| `name` | `string` |  | Field naming each point, shown in the tooltip. |
| `onHiddenGroupsChange` | `((hidden: string[]) => void)` |  |  |
| `onPointClick` | `((row: T) => void)` |  |  |
| `onRetry` | `(() => unknown)` |  |  |
| `referenceAreas` | `readonly ChartReferenceArea[]` |  |  |
| `referenceLines` | `readonly ChartReferenceLine[]` |  |  |
| `showGrid` | `boolean` |  |  |
| `showLegend` | `boolean` |  |  |
| `size` | `string` |  | Field for the point size. Turns the scatter into a bubble chart. |
| `sizeFormatter` | `((value: number) => string)` |  | Formats `size` in the tooltip. |
| `sizeRange` | `readonly [number, number]` |  | Smallest and largest bubble area in pixels. Default `[40, 600]`. |
| `xAxis` | `ChartAxisOptions` |  | Axis titles and tick formatters. Name the axes: a scatter has no other labels. |
| `yAxis` | `ChartAxisOptions` |  |  |

## Example: Bubble chart

Accounts by seats and MRR, sized by open tickets and grouped by segment.

```tsx
import { ScatterChart } from '@glyphui/ui/chart'

const accounts = [
  { name: 'Northwind', seats: 42, mrr: 1240, tickets: 3, segment: 'SMB' },
  { name: 'Initech', seats: 18, mrr: 420, tickets: 1, segment: 'SMB' },
  { name: 'Vandelay', seats: 35, mrr: 910, tickets: 6, segment: 'SMB' },
  { name: 'Umbrella', seats: 96, mrr: 2380, tickets: 4, segment: 'Mid-market' },
  { name: 'Contoso', seats: 140, mrr: 3900, tickets: 9, segment: 'Mid-market' },
  { name: 'Soylent', seats: 120, mrr: 2600, tickets: 2, segment: 'Mid-market' },
  { name: 'Globex', seats: 260, mrr: 8200, tickets: 12, segment: 'Enterprise' },
  { name: 'Hooli', seats: 340, mrr: 12900, tickets: 7, segment: 'Enterprise' },
  { name: 'Wayne', seats: 410, mrr: 11200, tickets: 15, segment: 'Enterprise' },
]

export default function Example() {
  return (
    <ScatterChart
      className="w-full"
      title="Accounts by size and revenue"
      description="Bubble size is open support tickets"
      data={accounts}
      x="seats"
      y="mrr"
      size="tickets"
      name="name"
      groupBy="segment"
      xAxis={{ label: 'Seats' }}
      yAxis={{ label: 'MRR', formatter: (v: number) => `$${(v / 1000).toFixed(0)}k` }}
    />
  )
}
```

Live page: https://glyphui.xyz/components/scatter-chart
