File size: 1,329 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
---
title: Scatter Chart
description: Used to show the relationship between two sets of data
links:
  storybook: charts-scatter-chart--basic
  recharts: https://recharts.org/en-US/api/ScatterChart
---

<ExampleTabs name="charts/scatter-chart-basic" />

## Usage

```tsx
import { Chart, useChart } from "@chakra-ui/charts"
import { Scatter, ScatterChart, XAxis, YAxis } from "recharts"
```

```tsx
<Chart.Root>
  <ScatterChart>
    <XAxis />
    <YAxis />
    <Scatter />
  </ScatterChart>
</Chart.Root>
```

## Examples

### Multiple

Here's an example of a scatter chart with multiple series.

<ExampleTabs name="charts/scatter-chart-multiple" />

### Legend

Render the `Chart.Legend` component to display a legend for the scatter chart.

<ExampleTabs name="charts/scatter-chart-legend" />

### Trend Line

Here's an example that shows a trend line on the chart using the least squares
regression method.

To show the trend line, we're using the `Scatter` component from the `recharts`
library.

```tsx
<Scatter data={trendLine} shape={() => <Fragment />} />
```

<ExampleTabs name="charts/scatter-chart-trend-line" />

### Connect Dots

To draw a line between the dots, pass the `line` prop to the `Scatter`
component.

```tsx
<Scatter line={{ stroke: "red" }} />
```

<ExampleTabs name="charts/scatter-chart-connect-dots" />