Data structure
Recharts works with plain JavaScript arrays of objects. Each object represents a data point.Basic data format
Each object can have any number of properties. Recharts accesses these properties using the
dataKey prop.Nested data
Data can include nested objects:Array data
For scatter plots or bubble charts, data points can be coordinate pairs:The dataKey prop
ThedataKey prop is the primary mechanism for connecting data to visual elements. It specifies which property to extract from each data object.
String dataKey
Most common usage - a string property name:Function dataKey
For complex data transformations, use a function:Function
dataKey receives the entire data point object and should return a value that can be plotted.Nested dataKey with dot notation
Layout prop
Thelayout prop determines the orientation of the chart and how axes are mapped to data.
Horizontal layout (default)
In horizontal layout:- XAxis represents the category (discrete values)
- YAxis represents the value (continuous values)
- Bars/lines grow vertically
Vertical layout
In vertical layout:- XAxis represents the value (continuous values)
- YAxis represents the category (discrete values)
- Bars/lines grow horizontally
- Horizontal (default)
- Vertical
Polar layouts
Polar charts use different layout values:Coordinate systems
Recharts transforms your data through coordinate systems to determine pixel positions.Cartesian coordinate system
Cartesian charts use X and Y coordinates:- Domain: The range of your data values (e.g., 0 to 1000)
- Range: The pixel range available (e.g., 0 to 400)
- Scale: The function that maps domain to range
In SVG, the Y-axis increases downward. Recharts automatically inverts it so higher values appear at the top.
Polar coordinate system
Polar charts use angles and radii:Axis types
Recharts supports different axis types that determine how data is scaled.Category axis
For discrete, non-numeric values:Category axes distribute items evenly regardless of their actual values. Each category gets equal spacing.
Number axis
For continuous numeric values:Number axes scale proportionally. A value of 25 appears halfway between 0 and 50.
Domain configuration
Thedomain prop controls the range of values displayed on an axis.
Auto domain (default)
Recharts automatically calculates domain from data:Fixed domain
Explicitly set min and max:Dynamic domain
Use special keywords:Function domain
Calculate domain dynamically:- Zero baseline
- Data range
- Symmetric
Always start from zero for better comparison:
Data transformations
Stacking data
Multiple bars or areas with the samestackId are stacked:
- First bar starts from baseline (0 or domain min)
- Second bar starts where first bar ends
- Third bar starts where second bar ends
Percentage stacking
Normalize stacks to 100%:Synchronized charts
Share interactions across multiple charts:Charts with the same
syncId synchronize their tooltip positions and active states.Data point coordinates
Access computed coordinates in custom components:cx,cy: Center coordinates (for dots, scatter points)x,y: Top-left coordinates (for bars, rectangles)width,height: Dimensions (for bars, rectangles)payload: Original data objectvalue: The plotted value fromdataKey