Recharts was built for React developers, so a chart is just another component tree. In this Recharts React tutorial you will go from an empty component to a responsive, styled line chart and learn the mental model that applies to every other chart type.
1. Install the package
Add Recharts and react-is to an existing React project (Vite, Next.js or any other setup works):
npm install recharts react-is
Make sure react-is matches your React version — the npm guide explains why.
2. Shape your data as an array of objects
Recharts reads plain JavaScript arrays. Each object is one point on the x-axis, and each numeric property can become a series:
const data = [
{ month: "Jan", visitors: 2400, signups: 320 },
{ month: "Feb", visitors: 2810, signups: 410 },
{ month: "Mar", visitors: 3290, signups: 380 },
{ month: "Apr", visitors: 3050, signups: 460 },
{ month: "May", visitors: 3720, signups: 520 },
];
The property names are up to you. You connect them to the chart with the dataKey prop.
3. Compose the chart
A chart container receives the data, and its children describe what to draw. Each child is a distinct component:
import {
LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend,
} from "recharts";
export function TrafficChart() {
return (
<LineChart width={640} height={320} data={data}
margin={{ top: 10, right: 20, bottom: 0, left: 0 }}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="month" />
<YAxis />
<Tooltip />
<Legend />
<Line type="monotone" dataKey="visitors" stroke="#5B54D6" strokeWidth={2} />
<Line type="monotone" dataKey="signups" stroke="#1D8657" strokeWidth={2} />
</LineChart>
);
}
Remove the <Legend /> line and the legend disappears; swap Line for Bar inside a BarChart and you have a bar chart. That composability is the core idea of the library.
4. Make it responsive
Fixed widths are fine for experiments, but dashboards need charts that adapt to their container. Wrap the chart in ResponsiveContainer:
import { ResponsiveContainer } from "recharts";
<ResponsiveContainer width="100%" height={320}>
<LineChart data={data}>
{/* same children as before */}
</LineChart>
</ResponsiveContainer>
ResponsiveContainer measures its parent. If you use a percentage height, the parent element must have a real height, otherwise the chart collapses to zero. A fixed pixel height is the simplest fix.
The responsive charts guide covers aspect ratios, minimum heights and grid layouts in more depth.
5. Style the chart
Because Recharts renders SVG, styling is done with props that map to SVG attributes:
strokeandstrokeWidthset line colour and thickness.dot={false}hides point markers, or pass an object to style them.type="monotone"draws smooth curves;"linear"draws straight segments.- Axis props such as
tickLine,axisLineandtickFormattercontrol labels.
<YAxis tickFormatter={(v) => `${v / 1000}k`} axisLine={false} tickLine={false} />
<Line dataKey="visitors" stroke="#5B54D6" strokeWidth={3} dot={false} />
6. Customise the tooltip
The default tooltip works out of the box, and you can replace its content with your own component through the content prop:
function MyTooltip({ active, payload, label }) {
if (!active || !payload?.length) return null;
return (
<div className="chart-tip">
<strong>{label}</strong>
{payload.map((p) => (
<div key={p.dataKey}>{p.name}: {p.value}</div>
))}
</div>
);
}
<Tooltip content={<MyTooltip />} />
7. Using it in Next.js
Recharts components run in the browser. In the Next.js App Router, put your chart in a client component by adding "use client" at the top of the file, then import that component from your server pages.
Where to go next
You now know the pattern used by every Recharts chart: data array, container, composable children. Browse the Recharts examples guide for bar, area, pie and composed charts, or see how shadcn/ui builds themed charts on top of Recharts.
Plan the chart around a question
Before opening an editor, decide what a reader should learn from the visual. A line chart is suited to a question about change over time; a bar chart is usually better when the task is to compare named categories. This distinction sounds elementary, yet it determines the appropriate axes, labels, tooltip behaviour and handling of missing values. A dashboard becomes more persuasive when every chart has one clear analytical purpose rather than attempting to display everything the dataset contains.
For a visitor-tracking example, the question might be whether registrations are keeping pace with traffic. Place visitors and registrations in separate series only when their relative scales still allow a meaningful comparison. If one series is dramatically larger, percentages, separate panels or a carefully labelled secondary view may reveal more than two lines compressed against one axis. Chart composition is not merely an exercise in arranging components: it is the process of choosing an honest explanation.
Prepare data before rendering
Recharts expects stable, predictable objects. Keep dates in chronological order, make category labels consistent and convert numeric strings to real numbers before passing the array into a chart. Missing data deserves deliberate treatment: zero means an observed absence, whereas an absent or null value may mean no measurement was made. Confusing those cases can manufacture a dramatic drop that never occurred in the underlying activity. Cleaning the source data is often more consequential than adjusting the chart’s appearance.
In a production React application, separate data transformation from presentation. A utility can map API responses into the fields your chart needs, while the component concentrates on plotting those fields. Memoisation may help with expensive transformations, but it should not be used automatically for every small array. Use stable identifiers when building customised labels or interactive rows. Finally, test with empty data, a single observation and unusually long category names; a chart that survives those cases is far closer to being ready for real users.
Build a readable visual hierarchy
Choose a colour for each series that can be distinguished from the others, and keep those colours consistent wherever the same measure appears. The primary series might carry a saturated purple stroke, while supporting data uses blue or orange. Consider contrast against the plot background, especially for thin lines and small markers. Reduce unnecessary gridlines, but retain enough structure for a reader to estimate values. A legend identifies the series; a descriptive chart title explains why they matter.
Tooltips should supply exact figures without becoming the sole means of understanding the chart. A person using a keyboard or assistive technology may not be able to hover in the same way as a mouse user. Provide an accessible textual summary or a small data table when the figures are important. Format thousands, percentages, currencies and dates consistently. A tooltip that says “2,450 visits” is easier to interpret than an unlabeled value of “2450”, particularly when several measures coexist.
Think in responsive components
Responsiveness begins with the space allocated by the surrounding interface. A percentage width is useful only when the parent has an observable width, and a percentage height requires a parent with a defined height. ResponsiveContainer can adapt a chart to available dimensions, but it cannot invent dimensions that the layout does not supply. In card-based dashboards, define a sensible minimum height and check what happens when the containing grid shrinks from three columns to one.
On small screens, preserving every desktop label is seldom desirable. Reduce tick density, shorten month names when they remain unambiguous, and give the tooltip enough space to remain visible. For particularly crowded data, offer a shorter time range rather than squeezing dozens of points together. Verify the layout at realistic mobile widths, not merely at the default responsive breakpoint in a design tool. A chart that is technically resizable but illegible is not a responsive design success.
Refine and maintain the component
Extract repeated visual decisions into shared constants: colour tokens, number formatters, margins and tooltip typography. Keep the data keys explicit so future contributors understand which fields drive the visual. When a chart becomes difficult to follow, separate its wrapper, presentation and tooltip into smaller functions with clear names. Resist abstracting a single example into a configurable chart framework too early; reusable code should emerge from repeated requirements, not anticipation alone.
Before release, review the chart with the same seriousness as a form or table. Check that it works when the dataset changes, that loading and empty states are purposeful, and that error messages do not expose raw implementation details. Compare the visual against its source numbers to catch accidental sorting or aggregation mistakes. The final test is editorial: can an unfamiliar reader describe what the chart shows in one sentence? If not, its explanatory design needs another pass.
Conclusion
A strong first Recharts chart joins three disciplines: dependable data preparation, thoughtful component composition and clear visual communication. Begin with a small working example, make its dimensions explicit and refine its presentation against real user questions. With those habits in place, additional chart types become variations on a reliable approach rather than unrelated experiments.

