Axis basics
XAxis configuration
The X-axis typically represents categories or time:YAxis configuration
The Y-axis typically represents values:dataKey is needed for Y-axis—it automatically uses the data from your Line, Bar, or Area components.
Axis types
Axes can handle different data types:Category axis
Treats data as distinct values with equal spacing:https://github.com/recharts/recharts/blob/main/src/cartesian/XAxis.tsx:51-62
Number axis
Treats data as continuous numeric range:https://github.com/recharts/recharts/blob/main/src/cartesian/YAxis.tsx:62-74
Auto type
Infers the type based on chart layout:Axis domains
Control the range of values displayed on an axis.Auto domain
Let Recharts calculate the domain from your data:Fixed domain
Set explicit min and max values:Data-based domain
Use data min/max values:Domain with padding
Add padding to data min/max:https://github.com/recharts/recharts/blob/main/src/cartesian/YAxis.tsx:76-108
Function-based domain
Calculate domain dynamically:https://github.com/recharts/recharts/blob/main/src/cartesian/XAxis.tsx:105-107
Allow data overflow
Prevent clipping when data exceeds domain:Axis ticks
Custom tick count
Suggest the number of ticks:This is a suggestion—Recharts may adjust it for nice round numbers.
Custom tick values
Specify exact tick positions:https://github.com/recharts/recharts/blob/main/src/cartesian/XAxis.tsx:148-153
Tick formatting
Customize tick labels:Nice ticks algorithm
Control how Recharts calculates “nice” tick values:https://github.com/recharts/recharts/blob/main/src/cartesian/YAxis.tsx:205-214
Tick interval
Control which ticks are shown:https://github.com/recharts/recharts/blob/main/src/cartesian/XAxis.tsx:167-170
Min tick gap
Minimum spacing between tick labels:https://github.com/recharts/recharts/blob/main/src/cartesian/XAxis.tsx:160-165
Axis styling
Axis size
Control axis dimensions:https://github.com/recharts/recharts/blob/main/src/cartesian/XAxis.tsx:72-76, https://github.com/recharts/recharts/blob/main/src/cartesian/YAxis.tsx:150-156
Axis line
Customize the axis line:Tick line
Control tick marks:Tick label styling
Style tick text:tick: Tick text properties (orfalseto hide)angle: Rotation angle in degreestextAnchor: Text alignmentfontSize: Font sizeletterSpacing: Letter spacing for width calculation
https://github.com/recharts/recharts/blob/main/src/cartesian/XAxis.tsx:133-146, https://github.com/recharts/recharts/blob/main/src/cartesian/YAxis.tsx:176-204
Tick margin
Space between tick line and label:https://github.com/recharts/recharts/blob/main/src/cartesian/YAxis.tsx:186-189
Advanced axis features
Multiple axes
Use multiple axes for different data scales:https://github.com/recharts/recharts/blob/main/src/cartesian/XAxis.tsx:64-71, https://github.com/recharts/recharts/blob/main/src/cartesian/YAxis.tsx:120-126
Axis orientation
Flip axis position:https://github.com/recharts/recharts/blob/main/src/cartesian/XAxis.tsx:83-86, https://github.com/recharts/recharts/blob/main/src/cartesian/YAxis.tsx:162-166
Reversed axis
Reverse the direction:Mirror axis
Flip labels to inside the chart:https://github.com/recharts/recharts/blob/main/src/cartesian/XAxis.tsx:78-81
Axis padding
Add padding at axis edges:{ left: 0, right: 0 } for XAxis and { top: 0, bottom: 0 } for YAxis.
Source: https://github.com/recharts/recharts/blob/main/src/cartesian/XAxis.tsx:155-159, https://github.com/recharts/recharts/blob/main/src/cartesian/YAxis.tsx:167-172
Scale type
Use different scale functions:https://github.com/recharts/recharts/blob/main/src/cartesian/XAxis.tsx:111-131, https://github.com/recharts/recharts/blob/main/src/cartesian/YAxis.tsx:99-119
Hide axis
Hide the entire axis:CartesianGrid
Add background grid lines to your chart.Basic grid
Grid customization
https://github.com/recharts/recharts/blob/main/src/cartesian/CartesianGrid.tsx:181-188
Grid visibility
Control which grid lines show:https://github.com/recharts/recharts/blob/main/src/cartesian/CartesianGrid.tsx:92-103
Grid fill
Add background colors:https://github.com/recharts/recharts/blob/main/src/cartesian/CartesianGrid.tsx:119-161
Custom grid points
Specify exact grid line positions:https://github.com/recharts/recharts/blob/main/src/cartesian/CartesianGrid.tsx:105-117
Sync with ticks
Align grid lines with axis ticks:false.
Source: https://github.com/recharts/recharts/blob/main/src/cartesian/CartesianGrid.tsx:163-169
Multiple axes
Specify which axis the grid follows:https://github.com/recharts/recharts/blob/main/src/cartesian/CartesianGrid.tsx:190-198
Best practices
YAxis auto widthSet
width="auto" on YAxis to automatically adjust based on the widest tick label. This is useful for dynamic data ranges.