Chart composition model
Every Recharts chart is composed of three types of components:- Chart containers - The top-level component that defines the chart type
- Graphical items - Components that render data (Line, Bar, Area, etc.)
- Supporting components - Axes, grids, tooltips, legends, and labels
Chart containers
Chart containers provide the coordinate system and manage the rendering context for child components.Cartesian charts
Cartesian charts use X and Y axes:Cartesian charts automatically manage coordinate transformations and provide contexts consumed by XAxis, YAxis, and graphical items like Line, Bar, and Area.
Polar charts
Polar charts use angular and radial coordinates:Graphical items
Graphical items render your data. They consume the chart context and axes to transform data into visual elements.Line component
Renders data as connected points:- Props
- Source reference
dataKey: The key in data array to plot (required)type: Curve interpolation (monotone,linear,step, etc.)stroke: Line colorstrokeWidth: Line thicknessdot: Show/customize dots at data pointsactiveDot: Customize active dot on hover
Bar component
Renders data as rectangular bars:Area component
Renders data as filled area under a line:Multiple graphical items
Combine multiple graphical items in one chart:Axes components
Axes define the scale and orientation for plotting data.XAxis and YAxis
Cartesian axes for horizontal and vertical dimensions:XAxis typically uses
type="category" (discrete values) while YAxis uses type="number" (continuous values). These defaults are inferred from the chart layout.Multiple axes
Use multiple axes for different data scales:PolarAngleAxis and PolarRadiusAxis
Axes for polar coordinate systems:Grid components
Grids add visual guides to help read values.CartesianGrid
PolarGrid
Interactive components
Tooltip
Display data on hover:The Tooltip component automatically detects the tooltip event type based on the chart. LineChart and AreaChart default to
axis tooltips, while PieChart defaults to item tooltips.Legend
Display a legend for multiple data series:Cursor
Customize the cursor shown on hover:Label components
Label
Add labels to axes, lines, or specific points:LabelList
Add labels to all data points:Customization components
Cell
Customize individual segments in Pie charts or bars:Customized
Render custom SVG content within the chart:Reference components
Add reference lines, areas, or dots to highlight specific values:Component hierarchy
The order of components matters for rendering and interactivity:Components are rendered in the order they appear in JSX. Place background elements first and interactive elements last for proper layering.
Context providers
Recharts uses React context internally to share state between components:- CartesianChartContext: Provides chart dimensions, layout, and data to XAxis, YAxis, and cartesian graphical items
- PolarChartContext: Provides polar coordinate system to PolarAngleAxis, PolarRadiusAxis, and polar graphical items
- ResponsiveContainerContext: Provides responsive dimensions to chart containers
You don’t need to interact with contexts directly. They’re managed automatically when you compose chart components.