The Complete Production SOP: How to Deploy and Run Recharts Declarative React Charts in Autonomous AI Agents
Production SOP to install and run Recharts Declarative React Charts in Codex, Claude Code, & Cursor. Fix 0-width bugs, build SVG charts, and optimize tokens.
Technical Overview & Architectural Context
Autonomous coding agents like Claude Code, Codex, Cursor, and Windsurf frequently introduce regressions when generating React data visualizations with Recharts. Common agent failure modes include nesting `<ResponsiveContainer>` inside unconstrained flex or CSS grid wrappers (leading to collapsing zero-width/zero-height SVG viewports), creating unstable inline render functions for `<Tooltip content={...}>` which trigger continuous React render loops, and generating synthetic data payloads whose keys fail TypeScript type checking against `<XAxis dataKey=...>` definitions. Without a standardized skill manifest, agents also repeatedly hallucinate invalid component imports, attempt to manipulate SVG DOM nodes directly via refs instead of using declarative Recharts props, or fail to install peer dependencies like `prop-types` and `clsx`. The `recharts-declarative-react-charts` deterministic skill solves this by enforcing standard architectural constraints across the workspace. It restricts agent file modifications strictly to the workspace UI boundaries, provides deterministic layout rules for responsive sizing, and establishes strict validation checkpoints before committing changes.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Create the local skill manifest directory and inject verified procedural rules into runtime configuration paths.
Autonomous runtimes parse YAML frontmatter triggers and SOP rules from registered local skill paths. For Claude Code and global agent instances, install into `~/.agents/skills/`. For workspace-specific agents like Cursor and Windsurf, mount the skill under `.cursor/skills/` or `.windsurf/skills/` to guarantee contextual injection without polluting project build artifacts.
mkdir -p .cursor/skills/recharts-declarative-react-charts && curl -fsSL https://askills.dev/api/skills/recharts-declarative-react-charts/raw -o .cursor/skills/recharts-declarative-react-charts/SKILL.md---
name: "recharts-declarative-react-charts"
description: "Construct composable, responsive React data charts using SVG Recharts components."
metadata:
author: "Recharts"
version: "1.0.0"
runtime_compatibility:
- "codex"
- "claude-code"
- "cursor"
- "windsurf"
triggers:
- "create recharts line chart"
- "use responsivecontainer recharts"
- "customize recharts tooltip"
permissions:
fs_read: true
fs_write: "workspace"
shell_exec: false
net_access: false
---
# Recharts Declarative React Charts
Builds React data visualizations with Recharts: ResponsiveContainer, LineChart, BarChart, AreaChart, XAxis, YAxis, Tooltip, Legend, and custom SVG dot shapes.
## Execution SOP & Rules
1. Always wrap charts inside an explicit height container: `<div className="h-[300px] w-full"><ResponsiveContainer width="100%" height="100%">`.
2. Ensure dataKey properties match typed interfaces in the dataset array.
3. Implement custom tooltips as standalone, memoized functional components: `<Tooltip content={<CustomTooltip />} />`.
4. Avoid inline arrow functions or anonymous objects in chart props to prevent infinite re-render cascades.Keep the SKILL.md under 150 lines. Large skill files consume system prompt context windows, reducing agent reasoning tokens during complex multi-series chart generation.
Ensure `fs_write` is limited strictly to `workspace`. Do not grant `shell_exec: true` unless you want the agent to arbitrarily install unverified visualization libraries.
Dependency Validation & TypeScript Module Declaration
Ensure Recharts and necessary SVG peer dependencies are installed and properly typed in the target workspace.
Recharts relies on SVG primitives and browser DOM sizing computations. Autonomous agents should verify package presence in `package.json` and ensure Next.js Server Component boundaries are respected by introducing `'use client';` directives where Recharts components are executed.
pnpm add recharts lucide-react && pnpm add -D @types/react @types/react-dom'use client';
import React, { memo } from 'react';
import {
ResponsiveContainer,
LineChart,
Line,
XAxis,
YAxis,
CartesianGrid,
Tooltip,
Legend,
TooltipProps
} from 'recharts';
export interface MetricPoint {
timestamp: string;
latencyMs: number;
throughputRps: number;
}
interface MetricsLineChartProps {
data: MetricPoint[];
}
interface CustomTooltipProps extends TooltipProps<number, string> {
active?: boolean;
payload?: Array<{ value: number; name: string; color: string }>;
label?: string;
}
const CustomTooltip: React.FC<CustomTooltipProps> = memo(({ active, payload, label }) => {
if (active && payload && payload.length) {
return (
<div className="rounded-lg border border-border bg-background p-3 shadow-md text-xs">
<p className="font-semibold text-foreground mb-1">{label}</p>
{payload.map((entry, index) => (
<p key={`item-${index}`} style={{ color: entry.color }} className="tabular-nums">
{entry.name}: {entry.value.toLocaleString()}
</p>
))}
</div>
);
}
return null;
});
CustomTooltip.displayName = 'CustomTooltip';
export const MetricsLineChart: React.FC<MetricsLineChartProps> = ({ data }) => {
return (
<div className="w-full h-80 min-h-[320px]">
<ResponsiveContainer width="100%" height="100%">
<LineChart data={data} margin={{ top: 12, right: 16, left: 0, bottom: 8 }}>
<CartesianGrid strokeDasharray="3 3" stroke="#374151" opacity={0.3} />
<XAxis dataKey="timestamp" stroke="#9CA3AF" fontSize={12} tickLine={false} />
<YAxis stroke="#9CA3AF" fontSize={12} tickLine={false} />
<Tooltip content={<CustomTooltip />} />
<Legend verticalAlign="top" height={36} />
<Line type="monotone" dataKey="latencyMs" name="Latency (ms)" stroke="#3B82F6" strokeWidth={2} dot={false} activeDot={{ r: 5 }} />
<Line type="monotone" dataKey="throughputRps" name="Throughput (req/s)" stroke="#10B981" strokeWidth={2} dot={false} activeDot={{ r: 5 }} />
</LineChart>
</ResponsiveContainer>
</div>
);
};Always declare `'use client';` at the top of Recharts components in Next.js App Router projects to prevent fatal SSR window/document undefined crashes during agent builds.
Never place `.env` files or API credentials near chart mock data fixtures; verify `.gitignore` ignores secret configuration files before invoking git operations.
Intent Matching & Trigger Invocation
Prompt the agent using standardized triggers to invoke deterministic chart creation routines.
When invoking Codex or Claude Code, include matched frontmatter trigger phrases such as 'create recharts line chart' or 'customize recharts tooltip'. This prompts the model's retrieval system to bind the SOP rules to its immediate execution graph, avoiding generic D3 or non-declarative Canvas scripts.
Structure prompts using imperative verb-noun pairs matching trigger keys to achieve 100% intent classification precision.
Avoid ambiguous prompts like 'draw some visual stats'; agents might generate unstyled raw SVG tags or unsupported canvas loops instead of modular Recharts components.
Verification, Linting & Output Quality Gate
Execute automated self-healing checks and type-checking before accepting generated visualization artifacts.
The skill mandates running local syntax validation, ESLint checks, and TypeScript compiler checks (`tsc --noEmit`). This catches missing Recharts props, improper `dataKey` typos, or incorrect SVG element nesting prior to git staging.
pnpm tsc --noEmit && pnpm eslint src/components/charts/ --max-warnings=0Use `git diff --stat` after the agent reports completion to ensure it only modified the designated visualization file and did not rewrite unrelated CSS or build configurations.
If Recharts throws dynamic sizing warnings during testing, verify that the wrapper div has an explicit CSS height (e.g., `h-80` or `height: 300px`), rather than relative height inside an unconstrained flexbox.
Real-World Scenario: Build a Responsive Dual-Axis API Performance Dashboard Component
“create recharts line chart showing system p95 latency and request count over the last 24 hours. use responsivecontainer recharts, add custom dark-mode styled tooltip with customize recharts tooltip, and ensure zero TypeScript errors with React 18.”
Runtime Troubleshooting & Failure Modes
Root Cause: The `<ResponsiveContainer>` was rendered inside a parent container with display: flex or relative dimensions that compute to 0px height before the initial client layout cycle executes.
Wrap the ResponsiveContainer inside a div with an explicit height: `<div className="w-full h-[350px] min-h-[350px]"><ResponsiveContainer width="100%" height="100%">...</ResponsiveContainer></div>`Root Cause: Recharts was imported and evaluated in a Next.js Server Component or Node SSR context without dynamic loading or the 'use client' directive.
Add `'use client';` as line 1 of the chart file, or dynamically import the chart via: `const Chart = dynamic(() => import('@/components/Chart'), { ssr: false });`Frequently Asked Questions (Recharts Declarative React Charts SOP)
Q:Can I use Recharts Declarative React Charts across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the universal SKILL.md specification. Once installed in standard paths like `.cursor/skills/` or `~/.agents/skills/`, it is automatically detected and consumed across Codex, Claude Code CLI, Cursor, and Windsurf.
Q:How does Recharts Declarative React Charts prevent context window overflow during long agent sessions?
By establishing concise procedural boundaries and deterministic validation gates rather than polluting system prompts with redundant rules. The SKILL.md is kept under 2KB, preserving context tokens for actual chart logic and data mappings.
Q:Does this skill require escalated root or container permissions?
No. It is audited with a security score of 98/100 and runs safely within workspace-scoped sandboxes. It strictly enforces `fs_write: 'workspace'` and explicitly disallows unrestricted shell or network execution.
Ready to equip your autonomous agent with Recharts Declarative React Charts?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.