recharts
A guide for implementing composable, responsive data charts in React apps.
Install
mkdir -p .claude/skills/recharts && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/12806" && unzip -o skill.zip -d .claude/skills/recharts && rm skill.zipInstalls to .claude/skills/recharts
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Build composable, responsive React charts with Recharts library. Use when creating data visualizations including line charts, area charts, bar charts, pie charts, scatter plots, and composed charts. Handles chart customization, responsive sizing, tooltips, legends, axes configuration, performance optimization, and accessibility.Key capabilities
- →Install Recharts library
- →Create line charts with `LineChart` and `Line` components
- →Build area charts using `AreaChart` and `Area` components
- →Construct bar charts with `BarChart` and `Bar` components
- →Generate pie charts using `PieChart` and `Pie` components
- →Develop composed charts by mixing chart types
How it works
This skill uses the Recharts library to build React charts by composing specialized components like `LineChart`, `XAxis`, and `Tooltip`, with data provided as an array of objects.
Inputs & outputs
When to use recharts
- →Create line chart
- →Build bar graph
- →Implement dashboard visualization
About this skill
Recharts
React charting library built on top of D3 for composable, declarative data visualization.
Quick Start
1. Install Recharts
npm install recharts
2. Basic Chart Structure
All Recharts charts follow the same pattern:
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer } from 'recharts';
const data = [
{ name: 'Jan', sales: 4000, profit: 2400 },
{ name: 'Feb', sales: 3000, profit: 1398 },
{ name: 'Mar', sales: 2000, profit: 9800 },
];
<ResponsiveContainer width="100%" height={300}>
<LineChart data={data}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey="name" />
<YAxis />
<Tooltip />
<Legend />
<Line type="monotone" dataKey="sales" stroke="#8884d8" />
<Line type="monotone" dataKey="profit" stroke="#82ca9d" />
</LineChart>
</ResponsiveContainer>
Core Concepts
Data Format
Recharts expects data as an array of objects. Each object represents a data point:
const data = [
{ month: 'Jan', revenue: 4000, expenses: 2400 },
{ month: 'Feb', revenue: 3000, expenses: 1398 },
];
Use dataKey props to map object properties to chart components:
dataKey="revenue"- maps to the revenue propertydataKey={(entry) => entry.revenue - entry.expenses}- function for computed values
Component Composition
Charts are built by nesting specialized components:
Sizing: Use the responsive prop (v3.3+), ResponsiveContainer wrapper, or set width/height directly
Chart types (choose one):
LineChart- Line and area visualizationsBarChart- Bar and column chartsAreaChart- Stacked and filled area chartsPieChart- Pie and donut chartsScatterChart- Scatter plots and bubble chartsComposedChart- Mixed chart typesRadarChart- Radar/spider chartsRadialBarChart- Circular bar charts
Common child components:
XAxis/YAxis- Axis configurationCartesianGrid- Grid linesTooltip- Hover informationLegend- Series identificationLine/Bar/Area/Pie- Data series visualization
Chart Patterns by Type
Line Charts
<LineChart data={data}>
<XAxis dataKey="name" />
<YAxis />
<CartesianGrid strokeDasharray="3 3" />
<Tooltip />
<Legend />
<Line type="monotone" dataKey="value" stroke="#8884d8" strokeWidth={2} dot={{ r: 4 }} />
</LineChart>
Key props:
type: "monotone" (smooth), "linear", "step", "natural"stroke: line colorstrokeWidth: line thicknessdot: point styling (set tofalseto hide)activeDot: hovered point stylingconnectNulls: true to connect gaps
Area Charts
<AreaChart data={data}>
<defs>
<linearGradient id="colorValue" x1="0" y1="0" x2="0" y2="1">
<stop offset="5%" stopColor="#8884d8" stopOpacity={0.8}/>
<stop offset="95%" stopColor="#8884d8" stopOpacity={0}/>
</linearGradient>
</defs>
<XAxis dataKey="name" />
<YAxis />
<CartesianGrid strokeDasharray="3 3" />
<Tooltip />
<Area type="monotone" dataKey="value" stroke="#8884d8" fillOpacity={1} fill="url(#colorValue)" />
</AreaChart>
Stacked areas:
<Area type="monotone" dataKey="sales" stackId="1" stroke="#8884d8" fill="#8884d8" />
<Area type="monotone" dataKey="profit" stackId="1" stroke="#82ca9d" fill="#82ca9d" />
Bar Charts
<BarChart data={data}>
<XAxis dataKey="name" />
<YAxis />
<CartesianGrid strokeDasharray="3 3" />
<Tooltip />
<Legend />
<Bar dataKey="sales" fill="#8884d8" radius={[4, 4, 0, 0]} />
<Bar dataKey="profit" fill="#82ca9d" radius={[4, 4, 0, 0]} />
</BarChart>
Key props:
fill: bar colorradius: rounded corners [topLeft, topRight, bottomRight, bottomLeft] or single number for all cornersbarSize: fixed bar widthstackId: group bars into stacksshape: custom bar shape (function or element)
Stacked bars:
<Bar dataKey="sales" stackId="a" fill="#8884d8" />
<Bar dataKey="profit" stackId="a" fill="#82ca9d" />
Rounded stacked bars (use BarStack to round the whole stack):
import { BarStack } from 'recharts';
<BarChart data={data}>
<BarStack stackId="a" radius={[4, 4, 0, 0]}>
<Bar dataKey="sales" fill="#8884d8" />
<Bar dataKey="profit" fill="#82ca9d" />
</BarStack>
</BarChart>
Pie Charts
const COLORS = ['#0088FE', '#00C49F', '#FFBB28', '#FF8042'];
<PieChart>
<Pie
data={data}
dataKey="value"
nameKey="name"
cx="50%"
cy="50%"
innerRadius={60}
outerRadius={80}
paddingAngle={5}
shape={(props) => <Sector {...props} fill={COLORS[props.index % COLORS.length]} />}
/>
<Tooltip />
<Legend />
</PieChart>
Key props:
innerRadius: creates donut chart when > 0outerRadius: pie sizepaddingAngle: gap between slicesstartAngle/endAngle: partial pie (default: 0 to 360)label: shows values on slicesshape: custom render for each slice (replaces deprecatedCellcomponent)
Scatter Charts
<ScatterChart>
<XAxis type="number" dataKey="x" name="X Axis" />
<YAxis type="number" dataKey="y" name="Y Axis" />
<CartesianGrid />
<Tooltip cursor={{ strokeDasharray: '3 3' }} />
<Scatter name="Series A" data={data} fill="#8884d8" />
</ScatterChart>
Composed Charts
Mix multiple chart types:
<ComposedChart data={data}>
<XAxis dataKey="name" />
<YAxis />
<CartesianGrid stroke="#f5f5f5" />
<Tooltip />
<Legend />
<Area type="monotone" dataKey="total" fill="#8884d8" stroke="#8884d8" />
<Bar dataKey="sales" barSize={20} fill="#413ea0" />
<Line type="monotone" dataKey="profit" stroke="#ff7300" />
</ComposedChart>
Responsive Sizing
Option 1: responsive prop (Recharts 3.3+, recommended)
Set responsive on the chart itself. Uses standard CSS sizing rules:
<LineChart data={data} width="100%" height={300} responsive>
{/* chart components */}
</LineChart>
Works with flexbox and CSS grid layouts. Also supports CSS style props:
<LineChart data={data} responsive style={{ maxWidth: 800, width: '100%', aspectRatio: '16/9' }}>
{/* chart components */}
</LineChart>
Option 2: ResponsiveContainer (older versions)
For Recharts < 3.3, wrap chart in ResponsiveContainer:
<ResponsiveContainer width="100%" height={300}>
<LineChart data={data}>
{/* chart components */}
</LineChart>
</ResponsiveContainer>
Critical: ResponsiveContainer must have a parent with defined dimensions. Height must be a number, not a percentage.
Static sizing
Set width and height directly as pixels or percentages:
<LineChart data={data} width={600} height={300}>
{/* chart components */}
</LineChart>
Axes Configuration
XAxis / YAxis Props
<XAxis
dataKey="name" // property to display
type="category" // "category" or "number"
domain={[0, 'dataMax']} // axis range
tick={{ fill: '#666' }} // tick styling
tickFormatter={(value) => `$${value}`} // format labels
angle={-45} // rotate labels
textAnchor="end" // text alignment
height={60} // extra space for labels
/>
Axis Types
- Category axis (default for X): Treats values as discrete labels
- Number axis (default for Y): Treats values as continuous scale
Custom Domains
Control axis range:
// Fixed range
<YAxis domain={[0, 100]} />
// Auto with padding
<YAxis domain={[0, 'auto']} />
// Data-based with overflow allowed
<YAxis domain={[0, 'dataMax + 100']} allowDataOverflow />
// Logarithmic scale
<YAxis type="number" scale="log" domain={['auto', 'auto']} />
Customization
Custom Tooltip
const CustomTooltip = ({ active, payload, label }) => {
if (active && payload && payload.length) {
return (
<div className="custom-tooltip">
<p className="label">{`${label}`}</p>
<p className="intro">{`Sales: ${payload[0].value}`}</p>
<p className="desc">Additional info...</p>
</div>
);
}
return null;
};
<Tooltip content={<CustomTooltip />} />
Custom Legend
const CustomLegend = ({ payload }) => (
<ul>
{payload.map((entry, index) => (
<li key={`item-${index}`} style={{ color: entry.color }}>
{entry.value}
</li>
))}
</ul>
);
<Legend content={<CustomLegend />} />
Custom Shapes
Custom bar shape:
const CustomBar = (props) => {
const { x, y, width, height, fill } = props;
return <path d={`M${x},${y} ...`} fill={fill} />;
};
<Bar shape={<CustomBar />} dataKey="sales" />
// OR
<Bar shape={(props) => <CustomBar {...props} />} dataKey="sales" />
Custom Labels
<Line
dataKey="sales"
label={{ position: 'top', fill: '#666', fontSize: 12 }}
/>
// Custom label component
<Line
dataKey="sales"
label={<CustomLabel />}
/>
Styling
Chart styles:
<LineChart style={{ backgroundColor: '#f5f5f5' }}>
Axis styling:
<XAxis
axisLine={{ stroke: '#666' }}
tickLine={{ stroke: '#666' }}
tick={{ fill: '#666', fontSize: 12 }}
/>
Grid styling:
<CartesianGrid strokeDasharray="3 3" stroke="#e0e0e0" />
Interactions
Active Elements and Interaction Control
The Tooltip component controls active element highlighting. Do not use activeIndex prop (removed in v3).
Tooltip interaction props:
defaultIndex: Sets initial highlighted item on renderactive: If true, tooltip remains active after interaction endstrigger:"hover"(default) or"click"for click-based interactioncontent: Custom content or() => nullto hide tooltip text while keeping highlightcursor: Visual cursor in plot area, set tofalseto hide
{/* Click-based interaction with hidden tooltip text */}
<Tooltip trigger="click" content={() => null} cursor={false} />
{/*
---
*Content truncated.*
When not to use it
- →When `ResponsiveContainer` has no parent with defined dimensions
- →When height is a percentage in `ResponsiveContainer`
- →When data is not an array of objects
Prerequisites
Limitations
- →Chart not rendering if `ResponsiveContainer` has no parent with defined dimensions
- →Tooltip not showing if `Tooltip` component is not included
- →Axis labels overlapping if not configured with `angle` or `interval`
How it compares
This workflow use a declarative React component-based approach for data visualization, allowing for composable and responsive charts, which differs from imperative chart drawing libraries.
Compared to similar skills
recharts side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| recharts (this skill) | 0 | 5mo | Review | Beginner |
| magicpath | 0 | 2mo | Review | Intermediate |
| react-email | 5 | 2mo | Review | Intermediate |
| web-development | 5 | 2mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by ihmorol
View all by ihmorol →You might also like
magicpath
tanglg
Search, preview, inspect, and install MagicPath UI components with the magicpath-ai CLI. Use when the user mentions MagicPath, wants to browse or search MagicPath components, preview one, or add one to their project. Also use when the user wants to create a new MagicPath project (workspace for desig
react-email
resend
Use when creating HTML email templates with React components - welcome emails, password resets, notifications, order confirmations, newsletters, or transactional emails.
web-development
TencentCloudBase
Web frontend project development rules. Use this skill when developing web frontend pages, deploying static hosting, and integrating CloudBase Web SDK.
infographic-structure-creator
antvis
Generate or update infographic Structure components for this repo (TypeScript/TSX in src/designs/structures). Use when asked to design, implement, or modify structure layouts (list/compare/sequence/hierarchy/relation/geo/chart), including layout logic, component composition, and registration.
webf-quickstart
openwebf
Get started with WebF development - setup WebF Go, create a React/Vue/Svelte project with Vite, and load your first app. Use when starting a new WebF project, onboarding new developers, or setting up development environment.
fullstack-guardian
Jeffallan
Use when implementing features across frontend and backend, building APIs with UI, or creating end-to-end data flows. Invoke for feature implementation, API development, UI building, cross-stack work.