This skill should be used when the user asks to "create a D3 visualization", "make a D3 chart", "build a d3js graph", "create a bar chart with D3", "make a scatter plot", "build a treemap", "create a force-directed graph", "make a choropleth map", "create a Sankey diagram", "build a sunburst chart", "make a line chart", "create a histogram", "build a heatmap", or mentions D3.js, d3js, data visualization with D3, or any specific chart type. Covers D3.js v7 with three output formats and optional creative/artistic mode.
Creates D3.js visualizations through guided interviews and offers artistic or direct implementation modes.
/plugin marketplace add reggiechan74/cc-plugins/plugin install d3-visualizations@cc-pluginsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
examples/react-component.tsxexamples/separate-js/chart.jsexamples/separate-js/index.htmlexamples/standalone.htmlreferences/animation-interaction.mdreferences/chart-patterns.mdreferences/d3-api-quick-reference.mdreferences/geographic-patterns.mdreferences/hierarchy-network-patterns.mdtemplates/boilerplate.htmltemplates/gallery/analysis.jsontemplates/gallery/animation.jsontemplates/gallery/annotation.jsontemplates/gallery/areas.jsontemplates/gallery/bars.jsontemplates/gallery/dots.jsontemplates/gallery/essays.jsontemplates/gallery/fun.jsontemplates/gallery/hierarchies.jsontemplates/gallery/index.jsonCreate any D3.js data visualization quickly and correctly using D3 v7. This skill supports two workflows: direct implementation (default) for fast, professional output, and creative mode for artistic, philosophy-driven visualizations. Three output formats are available: standalone HTML, HTML + separate JS, and React components.
These defaults apply to every visualization unless the user explicitly overrides them. The assumption is that the user will PDF, screenshot, or otherwise export the result for insertion into another document.
Every visualization MUST fit entirely within a single browser viewport (100vh) with no scrolling required. This is non-negotiable.
Implementation rules:
html, body { height: 100vh; overflow: hidden; } on standalone HTML outputbody { display: flex; flex-direction: column; } with flex: 1 on the chart container to fill available space0.5rem–0.75rem), gaps (0.5rem), and font sizeswidth: 100%; height: 100%) rather than fixed pixel dimensions1.2fr 1fr) and min-height: 0 on flex children to prevent overflowviewBox on SVGs — never set fixed width/height attributesstyle("height", "auto") on SVGs — let CSS control sizingpreserveAspectRatio="xMidYMid meet" on charts that need to maintain proportions (donut, pie, radial layouts)d3.schemeTableau10 or curated palettes. No rainbow, no random RGB.-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif). No external font loads.#f0f2f5), white chart panels with subtle box shadow#f3f4f6), gray tick labels (#6b7280), no heavy bordersDirect mode (default): Proceed to the discovery interview, then implement.
Creative mode: Activate when the user says "artistic", "creative", "manifesto", or "generative". Run the discovery interview, then follow the full Design Philosophy Creation process before implementing.
Before writing any code, use the AskUserQuestion tool to interview the user. This step is mandatory — never skip it, even if the initial request seems detailed.
Run the interview in three rounds to avoid overwhelming the user.
Ask these questions using AskUserQuestion (all four in a single call):
"What is the goal of this visualization?" (header: "Goal")
"Who is the audience?" (header: "Audience")
"Do you have a dataset, or should I generate sample data?" (header: "Data")
"What output format do you need?" (header: "Format")
After the user answers Round 1, ask these questions using AskUserQuestion:
"Do you have brand colors or a specific color scheme?" (header: "Colors")
"What chart type do you have in mind?" (header: "Chart type")
"Any specific features you need?" (header: "Features", multiSelect: true)
"Where should I save the output file(s)?" (header: "Output path")
After Round 2, ask these final questions using AskUserQuestion:
"What should the chart title/headline be?" (header: "Title")
"Where will this visualization be used?" (header: "Destination")
"What is the single key takeaway the viewer should get?" (header: "Takeaway")
"Any specific data points, events, or benchmarks to highlight?" (header: "Annotations")
Summarize the gathered requirements back to the user in a brief confirmation before starting implementation. Example:
Building a stacked area chart showing revenue trends over time, for an executive audience. Using your CSV at ./data/revenue.csv. Brand colors: #1a3a5c, #e07b39, #2d8659. Standalone HTML saved to ./charts/revenue-trend.html. Features: tooltips, animated load, print-optimized.
Then proceed to implementation.
With interview answers in hand, follow these steps:
Standalone HTML (default): Single self-contained .html file with D3 v7 loaded via CDN. Opens directly in any browser.
HTML + separate JS: An index.html file and a chart.js module. Cleaner code organization for larger visualizations. Requires a local server (python -m http.server) due to ES module imports.
React component: A .tsx component using useRef and useEffect to integrate D3 with React. For projects already using React.
Refer to examples/ for working templates of each format.
Apply any user-specified brand colors, audience-appropriate labeling, and data source from the interview. If the user provided brand hex codes, use those instead of the default palette.
Always use D3 v7 via ES module CDN:
<script type="module">
import * as d3 from "https://cdn.jsdelivr.net/npm/d3@7/+esm";
</script>
Follow the default visual style — clean and professional (NYT/FT-inspired):
{top: 40, right: 30, bottom: 50, left: 60} as a starting pointviewBoxSample data: When the user has no data, generate realistic inline mock data so the visualization works immediately. Use d3.range(), arrays of objects, or embedded JSON. Never leave data as a placeholder.
Every D3 visualization follows this pattern:
// 1. Dimensions and margins
const margin = {top: 40, right: 30, bottom: 50, left: 60};
const width = 800 - margin.left - margin.right;
const height = 500 - margin.top - margin.bottom;
// 2. Create SVG container
const svg = d3.select("#chart")
.append("svg")
.attr("viewBox", `0 0 ${width + margin.left + margin.right} ${height + margin.top + margin.bottom}`)
.append("g")
.attr("transform", `translate(${margin.left},${margin.top})`);
// 3. Scales
// 4. Axes
// 5. Data binding and rendering
// 6. Labels, legends, tooltips
// 7. Transitions and interactivity
When the user provides a data file, use D3's fetch utilities inside the <script type="module"> block:
// CSV → array of objects (values are strings by default — coerce numbers)
const data = await d3.csv("data.csv", d => ({
category: d.category,
value: +d.value, // coerce to number
date: new Date(d.date) // parse dates
}));
// JSON → parsed object/array
const data = await d3.json("data.json");
// TSV
const data = await d3.tsv("data.tsv", d3.autoType);
Important: Loading external files via d3.csv() / d3.json() requires HTTP — it will fail when opening the HTML directly from the filesystem (file:// protocol) due to CORS restrictions. Tell the user to serve the file locally:
python -m http.server 8000
# then open http://localhost:8000/chart.html
For standalone HTML that must open without a server, embed data inline as a JavaScript array instead of loading from a file.
For detailed patterns organized by chart type, consult the reference files:
references/chart-patterns.md — Bar, line, area, scatter, pie/donut, histogram, box plot, ridgeline, heatmapreferences/hierarchy-network-patterns.md — Treemap, sunburst, circle packing, force-directed graph, Sankey, chord diagram, dendrogramreferences/geographic-patterns.md — Choropleth, world/state maps, projections, GeoJSON/TopoJSON handlingreferences/animation-interaction.md — Transitions, zoom, brush, drag, tooltips, responsive resizeBefore delivering any visualization, verify:
viewBox for responsive sizingrole="img" and aria-label describing the visualization<title> element for screen readersd3.schemeTableau10 is a safe default; for maximum accessibility use Okabe-Ito or d3.schemeObservable10)Null / missing data: Always filter or coerce before binding to scales. Null values cause NaN in scale output, which renders invisible or broken elements.
const clean = data.filter(d => d.value != null && !isNaN(d.value));
CDN availability: The default CDN (cdn.jsdelivr.net) is reliable but not infallible. If building for offline or restricted environments, note this in the output and suggest downloading D3 locally:
<!-- Fallback: download d3.min.js and serve locally -->
<script type="module">
import * as d3 from "./d3.min.js";
</script>
Overflowing 100vh: When content exceeds the viewport despite the single-screen constraint:
top: 20, bottom: 30 instead of 40/50)minmax(0, 1fr) to let panels shrinkDate parsing: D3 v7's d3.csv() returns all values as strings. Always parse dates explicitly:
const parseDate = d3.timeParse("%Y-%m-%d");
const data = await d3.csv("data.csv", d => ({ ...d, date: parseDate(d.date) }));
When the user requests artistic or creative visualization, follow this two-phase process inspired by generative art practices.
Create a DATA VISUALIZATION PHILOSOPHY — an aesthetic movement for how data should be expressed visually through D3.js. Output as a .md file.
Name the movement (1-2 words): "Luminous Data" / "Structural Narratives" / "Chromatic Flows"
Articulate the philosophy (4-6 paragraphs) expressing how data manifests through:
Critical guidelines:
Philosophy examples:
"Luminous Data": Data as light — values encoded as luminance, density as glow, relationships as light interference. Visualization emerges from darkness, data points illuminating structure. Transitions are dawn and dusk. Interaction reveals hidden constellations. The result of painstaking calibration where every opacity and blend mode was refined by a master.
"Structural Narratives": Data as architecture — values become load-bearing beams, categories are floors, time is the corridor. Visualization reads like a building section drawing. Precise, technical, yet deeply human. Every line weight chosen with architectural rigor.
With the philosophy established, implement the visualization using D3.js, letting the philosophy guide every design decision — scales, color choices, transition easing, layout algorithm, interaction model. Follow all technical requirements from the Implementation Workflow above, but let the philosophy override default style choices.
For a comprehensive module-by-module reference of D3 v7 APIs, consult references/d3-api-quick-reference.md. Key modules:
| Module | Purpose |
|---|---|
| d3-selection | DOM manipulation, data joins |
| d3-scale | Map data to visual values (linear, band, ordinal, time, log) |
| d3-axis | Generate axes from scales |
| d3-shape | Lines, areas, arcs, pies, curves, symbols |
| d3-hierarchy | Treemaps, trees, pack, partition, stratify |
| d3-force | Force-directed layouts |
| d3-geo | Map projections and geographic paths |
| d3-transition | Animated transitions |
| d3-zoom | Pan and zoom behavior |
| d3-brush | Rectangular selection |
| d3-fetch | Load CSV, JSON, TSV data |
| d3-scale-chromatic | Color schemes (categorical, sequential, diverging) |
Consult these for detailed, chart-specific implementation patterns:
references/chart-patterns.md — Standard chart types (bar, line, area, scatter, pie, histogram, box plot, heatmap, ridgeline)references/hierarchy-network-patterns.md — Hierarchical and network visualizations (treemap, sunburst, circle packing, force-directed, Sankey, chord, dendrogram)references/geographic-patterns.md — Geographic visualizations (choropleth, projections, TopoJSON, GeoJSON)references/animation-interaction.md — Transitions, zoom, brush, drag, tooltips, responsive designreferences/d3-api-quick-reference.md — D3 v7 module-by-module API referenceWorking templates for each output format in examples/:
examples/standalone.html — Self-contained HTML with inline D3 bar chartexamples/separate-js/index.html + examples/separate-js/chart.js — Modular HTML + JS approachexamples/react-component.tsx — React component with D3 integrationNote: Example files use a scrollable layout with padding for readability as teaching samples. Production output should follow the
templates/boilerplate.htmlpattern (100vh,overflow: hidden, flex layout) per the Default Configuration above.
templates/boilerplate.html — Minimal HTML boilerplate with D3 v7 CDN, responsive SVG, and standard margin convention. Use as a starting point for standalone HTML visualizations.../../demo.html — Complete multi-chart interactive dashboard (energy production) demonstrating linked brush filtering, animated transitions, interactive legend toggle, and donut arc tweens in a single 100vh viewport.The templates/gallery/ directory contains 174 template configurations based on the Observable D3 Gallery, organized by category. Each config specifies the chart type, D3 modules, data shape, scales, key patterns, and implementation notes needed to reproduce that visualization.
templates/gallery/index.json — Master index of all categories and schematemplates/gallery/animation.json — 23 animated visualizations (bar chart race, animated treemap, zoomable sunburst, etc.)templates/gallery/interaction.json — 9 interactive patterns (brushable scatterplot, pannable chart, versor dragging, etc.)templates/gallery/analysis.json — 14 analytical charts (histogram, box plot, KDE, hexbin, contours, etc.)templates/gallery/hierarchies.json — 14 hierarchy layouts (treemap, circle packing, sunburst, icicle, dendrogram, etc.)templates/gallery/networks.json — 11 network diagrams (force-directed, Sankey, chord, arc diagram, edge bundling, etc.)templates/gallery/bars.json — 14 bar chart variants (stacked, grouped, diverging, Marimekko, calendar, etc.)templates/gallery/lines.json — 15 line chart types (multi-line, candlestick, parallel coordinates, slope chart, etc.)templates/gallery/areas.json — 11 area chart types (stacked, streamgraph, ridgeline, horizon, difference, etc.)templates/gallery/dots.json — 11 dot/scatter types (scatterplot, beeswarm, bubble map, spike map, SPLOM, etc.)templates/gallery/radial.json — 6 radial charts (pie, donut, radial area, radial stacked bar, radar/spider)templates/gallery/annotation.json — 8 annotation techniques (tooltips, inline labels, Voronoi labels, styled axes, etc.)templates/gallery/maps.json — 22 geographic visualizations (choropleth, projections, tiles, vector fields, star map, etc.)templates/gallery/essays.json — 4 explanatory/educational visualizationstemplates/gallery/fun.json — 12 creative/artistic visualizations (polar clock, word cloud, Voronoi stippling, etc.)When a user requests a specific chart type, consult the relevant gallery config to get the exact D3 modules, scale types, data shape, and key implementation patterns needed.
Use when working with Payload CMS projects (payload.config.ts, collections, fields, hooks, access control, Payload API). Use when debugging validation errors, security issues, relationship queries, transactions, or hook behavior.