Examples

Recharts Examples: Line, Bar, Area, Pie and Composed Charts Explained

Copy-ready Recharts examples for line, bar, area, pie, radar and composed charts, with notes on when each chart type is the right choice.

Custom editorial artwork showing four distinctive line, bar, area and scatter chart examples

The fastest way to learn a charting library is to see working code. These Recharts examples cover the chart types most dashboards need. Each snippet uses the same sample data so you can compare how the containers differ.

const data = [
  { name: "Mon", sales: 120, returns: 18 },
  { name: "Tue", sales: 180, returns: 22 },
  { name: "Wed", sales: 150, returns: 15 },
  { name: "Thu", sales: 210, returns: 30 },
  { name: "Fri", sales: 260, returns: 26 },
];

Line chart — trends over time

Use a line chart when the order of the x-axis matters and you care about direction and change.

<LineChart width={520} height={280} data={data}>
  <CartesianGrid strokeDasharray="3 3" />
  <XAxis dataKey="name" />
  <YAxis />
  <Tooltip />
  <Line type="monotone" dataKey="sales" stroke="#5B54D6" />
</LineChart>

Bar chart — comparing categories

Bars make it easy to compare discrete values side by side. Multiple Bar children render as grouped bars; give them the same stackId to stack them.

<BarChart width={520} height={280} data={data}>
  <CartesianGrid strokeDasharray="3 3" />
  <XAxis dataKey="name" />
  <YAxis />
  <Tooltip />
  <Legend />
  <Bar dataKey="sales" fill="#8884D8" radius={[6, 6, 0, 0]} />
  <Bar dataKey="returns" fill="#82CA9D" radius={[6, 6, 0, 0]} />
</BarChart>

Area chart — volume and cumulative totals

An area chart is a line chart with the space below filled in. It emphasises magnitude, which suits traffic or revenue totals.

<AreaChart width={520} height={280} data={data}>
  <defs>
    <linearGradient id="salesFill" x1="0" y1="0" x2="0" y2="1">
      <stop offset="5%" stopColor="#5B54D6" stopOpacity={0.35} />
      <stop offset="95%" stopColor="#5B54D6" stopOpacity={0} />
    </linearGradient>
  </defs>
  <XAxis dataKey="name" />
  <YAxis />
  <Tooltip />
  <Area type="monotone" dataKey="sales" stroke="#5B54D6" fill="url(#salesFill)" />
</AreaChart>

Because charts are SVG, you can define gradients and patterns inside <defs> and reference them by id — no extra library required.

Pie and donut charts — parts of a whole

Pie charts work best with a handful of slices. Set innerRadius to turn it into a donut, and use Cell to colour each slice.

const colors = ["#5B54D6", "#82CA9D", "#F2B33D", "#8884D8"];

<PieChart width={320} height={280}>
  <Pie data={data} dataKey="sales" nameKey="name" innerRadius={60} outerRadius={100}>
    {data.map((entry, i) => (
      <Cell key={entry.name} fill={colors[i % colors.length]} />
    ))}
  </Pie>
  <Tooltip />
</PieChart>

Composed chart — mixing series types

ComposedChart lets bars, lines and areas share the same axes. It is ideal for "value plus target" or "volume plus rate" views.

<ComposedChart width={520} height={280} data={data}>
  <CartesianGrid strokeDasharray="3 3" />
  <XAxis dataKey="name" />
  <YAxis />
  <Tooltip />
  <Bar dataKey="sales" fill="#8884D8" />
  <Line type="monotone" dataKey="returns" stroke="#C2404A" />
</ComposedChart>

Radar chart — comparing several dimensions

<RadarChart width={320} height={280} data={skills} outerRadius={100}>
  <PolarGrid />
  <PolarAngleAxis dataKey="skill" />
  <PolarRadiusAxis />
  <Radar dataKey="score" stroke="#5B54D6" fill="#5B54D6" fillOpacity={0.3} />
</RadarChart>

Other chart types worth knowing

  • ScatterChart for relationships between two numeric variables.
  • RadialBarChart for progress-style rings.
  • FunnelChart for conversion steps.
  • Treemap and Sankey for hierarchical and flow data.

Useful building blocks

ComponentWhat it adds
ReferenceLineA target or threshold line across the chart
BrushA range selector for zooming into long series
LabelListValue labels on bars or points
syncId propSynchronised tooltips across several charts

Choosing the right example

Pick a chart by the question it answers: trends need lines or areas, comparisons need bars, composition needs pies or stacked bars, and relationships need scatter plots. Wrap any of them in ResponsiveContainer for fluid layouts — the responsive guide shows how — and see the React tutorial if you are new to the composition model.

Match visual form to analytical intent

A chart should be selected according to the comparison its reader needs to make. Use a line when continuity through time matters and the order of observations is meaningful. Use bars when categories should be compared from a common baseline. An area chart adds visual weight to quantity and is appropriate when the magnitude of a changing series matters. Pie and donut charts communicate simple proportional relationships, but they become difficult to read when slices are numerous or similar in size.

Recharts makes these alternatives approachable because many supporting components are familiar across chart families. Yet shared APIs do not erase the communication differences between visual forms. Before choosing a component, write the question the graphic must answer. If the question concerns ranking, bars are often easier to judge than slices; if it concerns a trend, a sequence of points will communicate direction more clearly than a set of disconnected categories. Visual correctness starts before JSX is written.

Design line and area examples responsibly

Line charts imply an ordered connection between data points, so sort temporal values consistently and avoid joining unrelated categories as though they formed a continuous measurement. Mark important interruptions or missing observations rather than silently replacing them with zero. When several lines share an axis, compare their scales and ensure that the colours remain distinguishable. A subtle grid can help readers make approximate comparisons without overwhelming the plotted paths.

Area charts can be effective for volume, capacity and cumulative change, but translucent fills may conceal overlap or imply total quantities that the data does not support. When stacking several areas, verify that the measures can legitimately be added. A percentage-based stacked chart answers a different question from one displaying absolute totals. Show units clearly, especially when switching between those modes. Examples that disclose their underlying assumptions teach more than visually elaborate demonstrations with unexplained numbers.

Use bars and composed charts with restraint

Bar charts are comparatively straightforward to read because viewers compare lengths along a shared baseline. For ordinary positive quantities, preserve the zero baseline unless a special analytical reason requires another presentation, and then make the choice explicit. Sort categories by a meaningful value when ranking is the objective. Keep categorical names legible; a horizontal layout may serve long labels better than rotating every x-axis tick until it is almost unreadable.

A composed chart combines series types, such as bars for sales and a line for a conversion rate. This can be useful when two related measures need to appear together, but it also creates a risk of implying a relationship that has not been established. Explain the distinction between the measures and label units rigorously. Avoid adding a second axis merely to make two shapes look equally dramatic. In a well-designed composed example, the combination clarifies the story rather than making the dashboard seem more sophisticated.

Build useful interaction and annotation

The Tooltip, Legend, CartesianGrid and axis components help transform a raw geometric mark into a readable chart. Their value depends on configuration, however. Number formatters should communicate currency, duration or percentages consistently. Legends should use the same terminology as the surrounding narrative. Gridlines can be reduced when they distract from the principal trend, while reference lines and annotations may be appropriate when readers must assess a target or threshold.

Tooltips should add detail without hiding the underlying meaning. A chart should still communicate its central finding in a static screenshot or printed report. Provide descriptive headings, concise explanatory text and, when precision matters, a table or written summary of the values. If an organisation uses colour to indicate performance, do not rely on hue alone: clear labels and position help readers who cannot distinguish the colours. Treat accessibility as an aspect of graphic design, not an optional finishing touch.

Turn examples into reusable product patterns

Start with an example that illustrates one specific component or behaviour, then adapt its data model, number formatting and responsive container to the real interface. Keep prototypes small enough to test in isolation. Once two or three charts share the same colours and typography, extract the common visual choices into design tokens or helper functions. This gives dashboards a coherent vocabulary without obscuring the distinctive needs of each chart type.

Reusability should not mean a large configuration object that makes ordinary changes difficult to trace. A simple shared tooltip wrapper, a standard margin scheme and consistent label formatters often deliver most of the value. Test each pattern with empty data, very long labels and uneven numeric ranges. Choose examples for their clarity under real constraints, not only for their appearance with perfectly balanced demonstration data. The best reusable visual is one that keeps answering its question as the dataset evolves.

Conclusion

The best Recharts example is not the most ornate; it is the one whose visual form fits the question and whose labels disclose the meaning of the numbers. Choose components deliberately, simplify interaction where possible and test the result with realistic data. These principles turn example code into charts that remain useful when incorporated into a real product.