# React Native Scatter & Bubble Chart (Pro)

> React Native scatter and bubble charts for iOS, Android and the web: points by group with their own color and shape, area-true bubbles, a line of best fit, date or number x axes, tooltips for the nearest point, legend toggles, animated data, and a screen-reader summary with the correlation.

# Scatter & Bubble chart Pro

Two measures per row as points: does one rise with the other? `groupKey` colors and shapes points by group (with a legend that toggles them), `sizeKey` turns points into bubbles sized by area, and `showTrend` draws the least-squares line. Screen readers hear the ranges and how strongly the measures move together.

```tsx
import { ScatterChart } from '@patine-ui/pro';
```

## Live data

```tsx live
import { useState } from 'react';
import { View } from 'react-native';
import { Button } from 'patine-ui';
import { ScatterChart } from '@patine-ui/pro';

const regions = ['North', 'South', 'West'];
const roll = () =>
  Array.from({ length: 30 }, (_, i) => {
    const spend = 5 + Math.random() * 45;
    return { spend: Math.round(spend), sales: Math.round(spend * 1.6 + Math.random() * 25), deals: 2 + Math.round(Math.random() * 16), region: regions[i % 3] };
  });

export default function Example() {
  const [data, setData] = useState(roll);
  return (
    <View style={{ width: 380, gap: 8 }}>
      <Button size="sm" variant="outline" onPress={() => setData(roll())} style={{ alignSelf: 'flex-end' }}>Shuffle</Button>
      <ScatterChart
        data={data}
        xKey="spend"
        yKey="sales"
        sizeKey="deals"
        groupKey="region"
        xLabel="Ad spend ($K)"
        yLabel="Sales ($K)"
        sizeLabel="Deals"
        showTrend
        accessibilityLabel="Sales against ad spend, by region"
      />
    </View>
  );
}
```

## Example: flat prices by size

A housing site's sold listings: each dot is a flat, size against price, colored by neighbourhood and sized by rooms. The trend line shows what a square metre costs, and the dots far above it are the outliers.

```tsx live wide
import { View } from 'react-native';
import { ScatterChart } from '@patine-ui/pro';

const AREAS = { Centrum: 9800, 'De Pijp': 8200, Noord: 5900 };
const data = Array.from({ length: 36 }, (_, i) => {
  const area = Object.keys(AREAS)[i % 3] as keyof typeof AREAS;
  const size = 38 + ((i * 23) % 92);
  return { size, price: Math.round((size * AREAS[area] * (0.9 + ((i * 7) % 20) / 100)) / 1000), rooms: 1 + Math.floor(size / 32), area };
});

export default function Example() {
  return (
    <View style={{ width: '100%' }}>
      <ScatterChart
        data={data}
        xKey="size"
        yKey="price"
        sizeKey="rooms"
        groupKey="area"
        xLabel="Size (m²)"
        yLabel="Price (€K)"
        sizeLabel="Rooms"
        showTrend
        height={280}
        accessibilityLabel="Sold flats in Amsterdam: size against price, by neighbourhood"
      />
    </View>
  );
}
```

## Over time

```tsx live
import { ScatterChart } from '@patine-ui/pro';

const data = Array.from({ length: 40 }, (_, i) => ({ at: new Date(2026, 9, 1 + i), ms: 120 + ((i * 53) % 90) + (i > 30 ? 80 : 0) }));

export default function Example() {
  return (
    <ScatterChart
      data={data}
      xKey="at"
      yKey="ms"
      yLabel="Response time"
      valueFormatter={(v) => `${v} ms`}
      referenceLines={[{ value: 200, label: 'Budget' }]}
      style={{ width: 380 }}
    />
  );
}
```

## Props

The [shared chart props](./charts#shared-props), and:

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `xKey` / `yKey` | `string` | — | Numbers (or `Date`s on x). |
| `sizeKey` | `string` | — | Sizes each point by area: a bubble chart. |
| `groupKey` | `string` | — | Groups points into series with their own color, shape and legend toggle. |
| `series` | `{ key, label?, color? }[]` | — | Labels and colors for groups. |
| `xLabel` / `yLabel` / `sizeLabel` | `string` | the keys | Names in the tooltip and summary. |
| `showTrend` | `boolean` | `false` | The line of best fit. |
| `grid` | `'value' \| 'category' \| 'both' \| 'none'` | `'both'` | |
| `minValue` / `maxValue` | `number` | from the data | The y axis's ends. |
| `referenceLines` | `{ value, label?, color?, dashed? }[]` | — | |
| `maxRadius` | `number` | `18` | The biggest bubble. |
| `xFormatter` | `(x) => string` | — | |
| `defaultHidden` | `string[]` | — | Groups turned off at first. |
