File size: 1,656 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
---
title: Cartesian Grid
description: How to customize the cartesian grid of the charts component
---

This guide will show you how to customize the cartesian grid of the charts
component.

:::note

The charts component is built on top of [Recharts](https://recharts.org). For
advanced usage, refer to their documentation.

:::

## Usage

```tsx
import { CartesianGrid } from "recharts"
```

```tsx
<CartesianGrid />
```

This will render a default grid with light gray lines on both the X and Y axes.

## Customize Stroke

Modify the appearance of the grid lines using `stroke`, `strokeDasharray`, and
`opacity`

```tsx
<CartesianGrid stroke="#ccc" strokeDasharray="3 3" opacity={0.5} />
```

| Property          | Description                                              |
| ----------------- | -------------------------------------------------------- |
| `stroke`          | Changes the grid line color (e.g., `#ddd`, `red`, etc.). |
| `strokeDasharray` | Defines the dash pattern (e.g., `5 5` for dashed lines). |
| `opacity`         | Controls grid line transparency (0 to 1).                |

## Show/Hide Grid Lines

To control whether horizontal or vertical lines are displayed:

```tsx
<CartesianGrid vertical={false} horizontal={true} />
```

- `vertical={false}` → Hides vertical grid lines
- `horizontal={false}` → Hides horizontal grid lines
- `horizontal={true}` and `vertical={true}` → Shows both (default behavior)

## Remove Grid Lines

To remove the grid completely, simply omit the `CartesianGrid` component or
explicitly hide both horizontal and vertical lines:

```tsx
<CartesianGrid horizontal={false} vertical={false} />
```