Prerequisites
Before you begin, make sure you have:- Node.js 18 or higher installed
- A React application set up (React 16.8+)
- Basic understanding of React components
Create your first chart
1
Install Recharts
Install Recharts and its peer dependency
react-is:The
react-is version should match your installed React version.2
Prepare your data
Create a data array with objects. Each object represents a data point:
3
Import chart components
Import the chart components you need:
4
Render your chart
Compose your chart using declarative components:
Understanding the components
Your first chart uses several key Recharts components:LineChart- The container component that sets up the coordinate systemLine- Renders the line series using thedataKeyprop to specify which data field to visualizeXAxisandYAxis- Display the horizontal and vertical axesCartesianGrid- Adds the background grid linesTooltip- Shows data details on hoverLegend- Displays the legend for your data series
Customization examples
Multiple data series
The example above already shows two lines (pv and uv). Each Line component creates a separate series:
Change line style
Customize the line appearance with different interpolation types:basis, basisClosed, basisOpen, linear, linearClosed, natural, monotoneX, monotoneY, monotone, step, stepBefore, stepAfter.
Add dots to data points
Show dots at each data point:Connect null values
Handle missing data by connecting around null values:Understanding dataKey
ThedataKey prop tells components which field in your data objects to visualize. It can be:
- A string: Direct property access (
dataKey="uv") - A nested path: Dot notation for nested objects (
dataKey="user.name") - A function: Custom data accessor (
dataKey={(data) => data.value * 2})
Make it responsive
Wrap your chart inResponsiveContainer to make it adapt to its parent size:
Next steps
Explore examples
See more chart examples and variations
Core concepts
Learn about chart types and architecture
API reference
Explore all props and options
Customization
Learn how to style and customize charts