File size: 2,201 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
---
title: Axis
description: How to customize the axis of the charts component
---

This guide will show you how to customize the x and y axis of the charts
component.

:::note

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

:::

## X-Axis

### Custom Tick Formatting

To format the labels on the X-axis (e.g., abbreviate months from `January` to
`Jan` based on locale):

```tsx
<XAxis dataKey="date" tickFormatter={chart.formatDate({ month: "short" })} />
```

### Rotate X-Axis Labels

If labels overlap, rotate them for better readability:

```tsx
<XAxis dataKey="name" angle={-45} textAnchor="end" />
```

### Adjust X-Axis Padding

Control the spacing between the first and last tick labels:

```tsx
<XAxis dataKey="name" padding={{ left: 20, right: 20 }} />
```

### Hide X-Axis

If you need to remove the X-axis completely:

```tsx
<XAxis hide />
```

### Custom X-Axis Labels

Render custom labels using a function:

```tsx
<XAxis dataKey="name" tick={{ fontSize: 12, fill: "blue" }} />
```

## Y-Axis

### Set Domain

Define the minimum and maximum values manually:

```tsx
<YAxis domain={[0, "dataMax + 100"]} />
```

### Format Labels

For example, converting values to percentages:

```tsx
<YAxis tickFormatter={(value) => `${value}%`} />
```

### Adjust Width

Control the space allocated to Y-axis labels:

```tsx
<YAxis width={50} />
```

### Hide Y-Axis

To remove the Y-axis from the chart:

```tsx
<YAxis hide />
```

### Custom Grid Lines

Enable or remove grid lines tied to the Y-axis:

```tsx
<YAxis tickLine={false} axisLine={false} />
```

## Additional Customizations

### Multiple X or Y Axes

Overlay multiple axes in a single chart:

```tsx
<YAxis yAxisId="left" orientation="left" stroke="#8884d8" />
<YAxis yAxisId="right" orientation="right" stroke="#82ca9d" />
```

### Reference Lines

Highlight a specific value with a reference line:

```tsx
<ReferenceLine y={1000} stroke="red" label="Threshold" />
```

### Axis Ticks and Lines

Remove the tick and axis lines by setting them to false.

```tsx
<XAxis tickLine={false} axisLine={false} />
<YAxis tickLine={false} axisLine={false} />
```