d3-visualization
Provides instructions for D3.js SVG manipulation and data binding to create custom, complex visualizations.
Install
mkdir -p .claude/skills/d3-visualization && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/255" && unzip -o skill.zip -d .claude/skills/d3-visualization && rm skill.zipInstalls to .claude/skills/d3-visualization
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.
Guides creation of custom, interactive data visualizations with D3.js — bar/line/scatter charts, network diagrams, geographic maps, hierarchies, and real-time data updates with zoom/pan/brush interactions and animated transitions. Use when chart libraries (Highcharts, Chart.js) lack the customization needed and you require low-level control over data-driven DOM manipulation, scales, shapes, and layouts. Invoke when user mentions D3, d3.js, custom visualization, force-directed graph, or data-driven SVG.Key capabilities
- →Bind data to SVG elements using D3 joins
- →Create scales for data transformation
- →Generate axes and shapes
- →Implement animated transitions
- →Configure force simulations and hierarchies
How it works
It utilizes low-level DOM manipulation and data-join patterns to map data arrays to visual attributes, enabling custom rendering and interaction logic.
Inputs & outputs
When to use d3-visualization
- →Create custom force-directed graphs
- →Build interactive maps
- →Develop bespoke data-driven animations
About this skill
D3.js Data Visualization
Table of Contents
Overview
D3 provides low-level building blocks for data-driven DOM manipulation, visual encoding, layout algorithms, and interactions — enabling bespoke visualizations that chart libraries cannot provide.
Use D3 when: Chart libraries lack your specific design, you need full customization, you're building network graphs/hierarchies/maps, or animating data changes smoothly.
Prefer simpler tools when: Simple bar/line charts suffice (Chart.js, Highcharts), you need 3D (Three.js, WebGL), or datasets exceed 10K points without aggregation.
Core concepts: Data Joins (bind arrays to DOM elements), Scales (data values to visual values), Shapes (SVG path generation), Layouts (position calculation for networks/trees/maps), Transitions (animated state changes), Interactions (zoom/pan/drag/brush).
Skill Structure
- Getting Started: Setup, prerequisites, first visualization
- Selections & Data Joins: DOM manipulation, data binding
- Scales & Axes: Data transformation, axis generation
- Shapes & Layouts: Path generators, basic layouts
- Advanced Layouts: Force simulation, hierarchies, geographic maps
- Transitions & Interactions: Animations, zoom/pan/drag/brush
- Workflows: Step-by-step guides for common chart types
- Common Patterns: Reusable code templates
Workflows
Choose a workflow based on your current task:
Create Basic Chart Workflow
Use when: Building bar, line, or scatter charts from scratch
Time: 1-2 hours
Copy this checklist and track your progress:
Basic Chart Progress:
- [ ] Step 1: Set up SVG container with margins
- [ ] Step 2: Load and parse data
- [ ] Step 3: Create scales (x, y)
- [ ] Step 4: Generate axes
- [ ] Step 5: Bind data and create visual elements
- [ ] Step 6: Style and add interactivity
Step 1: Set up SVG container with margins
Create SVG element with proper dimensions. Define margins for axes: {top: 20, right: 20, bottom: 30, left: 40}. Calculate inner width/height: width - margin.left - margin.right. See Getting Started.
Step 2: Load and parse data
Use d3.csv('data.csv') for external files or define data array directly. Parse dates with d3.timeParse('%Y-%m-%d') for time series. Convert strings to numbers for CSV data using conversion function. See Getting Started.
Step 3: Create scales
Choose scale types based on data: scaleBand (categorical), scaleTime (temporal), scaleLinear (quantitative). Set domains from data using d3.extent(), d3.max(), or manual ranges. Set ranges from SVG dimensions. See Scales & Axes.
Step 4: Generate axes
Create axis generators: d3.axisBottom(xScale), d3.axisLeft(yScale). Append g elements positioned with transforms. Call axis generators: .call(axis). Customize ticks with .ticks(), .tickFormat(). See Scales & Axes.
Step 5: Bind data and create visual elements
Use data join pattern: svg.selectAll(type).data(array).join(type). Set attributes using scales and accessor functions: .attr('x', d => xScale(d.category)). For line charts, use d3.line() generator. For scatter plots, create circles with cx, cy, r attributes. See Selections & Data Joins and Shapes & Layouts.
Step 6: Style and add interactivity
Apply colors: .attr('fill', ...), .attr('stroke', ...). Add hover effects: .on('mouseover', ...) with tooltip. Add click handlers for drill-down. Apply transitions for initial animation (optional). See Transitions & Interactions and Common Patterns.
Update Visualization with New Data
Use when: Refreshing charts with new data (real-time, filters, user interactions)
Time: 30 minutes - 1 hour
Copy this checklist:
Update Progress:
- [ ] Step 1: Encapsulate visualization in update function
- [ ] Step 2: Update scale domains if needed
- [ ] Step 3: Re-bind data with key function
- [ ] Step 4: Add transitions to join
- [ ] Step 5: Update attributes with new values
- [ ] Step 6: Trigger update on data change
Step 1: Encapsulate visualization in update function
Wrap steps 3-5 from basic chart workflow in function update(newData) { ... }. This makes visualization reusable for any dataset. See Workflows.
Step 2: Update scale domains
Recalculate domains when data range changes: yScale.domain([0, d3.max(newData, d => d.value)]). Update axes with transition: svg.select('.y-axis').transition().duration(500).call(yAxis). See Selections & Data Joins.
Step 3: Re-bind data with key function
Use key function for object constancy: .data(newData, d => d.id). Ensures elements track data items, not array positions. Critical for correct transitions. See Selections & Data Joins.
Step 4: Add transitions to join
Insert .transition().duration(500) before attribute updates. Specify easing with .ease(d3.easeCubicOut). For custom enter/exit effects, use enter/exit functions in .join(). See Transitions & Interactions.
Step 5: Update attributes with new values
Set positions/sizes using updated scales: .attr('y', d => yScale(d.value)), .attr('height', d => height - yScale(d.value)). Transitions animate from old to new values. See Common Patterns.
Step 6: Trigger update on data change
Call update(newData) when data changes: button clicks, timers (setInterval), WebSocket messages, API responses. For real-time, use sliding window to limit data points. See Workflows.
Create Advanced Layout Workflow
Use when: Building network graphs, hierarchies, or geographic maps
Time: 2-4 hours
Copy this checklist:
Advanced Layout Progress:
- [ ] Step 1: Choose appropriate layout type
- [ ] Step 2: Prepare and structure data
- [ ] Step 3: Create and configure layout
- [ ] Step 4: Apply layout to data
- [ ] Step 5: Bind computed properties to elements
- [ ] Step 6: Add interactions (drag, zoom)
Step 1: Choose appropriate layout type
Force Simulation: Network diagrams, organic clustering. Hierarchies: Tree, cluster (node-link), treemap, pack, partition (space-filling). Geographic: Maps with projections. Chord: Flow diagrams. See Advanced Layouts for decision guidance.
Step 2: Prepare and structure data
Force: nodes = [{id, group}], links = [{source, target}]. Hierarchy: Nested objects with children arrays, convert with d3.hierarchy(data). Geographic: GeoJSON features. See Advanced Layouts.
Step 3: Create and configure layout
Force: d3.forceSimulation(nodes).force('link', d3.forceLink(links)).force('charge', d3.forceManyBody()). Hierarchy: d3.treemap().size([width, height]). Geographic: d3.geoMercator().fitExtent([[0,0], [width,height]], geojson). See Advanced Layouts for each layout type.
Step 4: Apply layout to data
Force: Simulation runs automatically, updates node positions each tick. Hierarchy: Call layout on root: treemap(root). Geographic: No application needed, projection used in path generator. See Advanced Layouts.
Step 5: Bind computed properties to elements
Force: Update cx, cy in tick handler: node.attr('cx', d => d.x). Hierarchy: Use d.x0, d.x1, d.y0, d.y1 for rectangles. Geographic: Use path(feature) for d attribute. See Workflows for layout-specific examples.
Step 6: Add interactions
Drag for force networks: node.call(d3.drag().on('drag', dragHandler)). Zoom for maps/large networks: svg.call(d3.zoom().on('zoom', zoomHandler)). Click for hierarchy drill-down. See Transitions & Interactions.
Path Selection Menu
What would you like to do?
-
I'm new to D3 - Setup environment, understand prerequisites, create first visualization
-
Build a basic chart - Bar, line, or scatter plot step-by-step
-
Transform data with scales - Map data values to visual properties (positions, colors, sizes)
-
Bind data to elements - Connect arrays to DOM elements, handle dynamic updates
-
Create network/hierarchy/map - Force-directed graphs, treemaps, geographic visualizations
-
Add animations - Smooth transitions between chart states
-
**[Add interactivity](resources/transitions-interac
Content truncated.
When not to use it
- →Avoid for simple bar or line charts where libraries suffice
- →Do not use for 3D visualizations
Limitations
- →Performance may degrade with datasets exceeding 10K points
- →Steep learning curve for advanced layouts
How it compares
It offers granular control over every visual element and transition, whereas standard chart libraries enforce rigid, pre-defined templates.
Compared to similar skills
d3-visualization side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| d3-visualization (this skill) | 7 | 4mo | No flags | Advanced |
| antv-l7 | 2 | 1mo | No flags | Intermediate |
| zustand | 113 | 2mo | No flags | Intermediate |
| threejs-skills | 61 | 4mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by lyndonkl
View all by lyndonkl →You might also like
antv-l7
antvis
Comprehensive guide for AntV L7 geospatial visualization library. Use when users need to: (1) Create interactive maps with WebGL rendering (2) Visualize geographic data (points, lines, polygons, heatmaps) (3) Build location-based data dashboards (4) Add map layers, interactions, or animations (5) Process and display GeoJSON, CSV, or other spatial data (6) Integrate maps with AMap (GaodeMap), Mapbox, Maplibre, or standalone L7 Map (7) Optimize performance for large-scale geographic datasets
zustand
lobehub
Zustand state management guide. Use when working with store code (src/store/**), implementing actions, managing state, or creating slices. Triggers on Zustand store development, state management questions, or action implementation.
threejs-skills
sickn33
Three.js skills for creating 3D elements and interactive experiences
accessibility-compliance
wshobson
Implement WCAG 2.2 compliant interfaces with mobile accessibility, inclusive design patterns, and assistive technology support. Use when auditing accessibility, implementing ARIA patterns, building for screen readers, or ensuring inclusive user experiences.
react-modernization
wshobson
Upgrade React applications to latest versions, migrate from class components to hooks, and adopt concurrent features. Use when modernizing React codebases, migrating to React Hooks, or upgrading to latest React versions.
3d-graphics
samhvw8
3D web graphics with Three.js (WebGL/WebGPU). Capabilities: scenes, cameras, geometries, materials, lights, animations, model loading (GLTF/FBX), PBR materials, shadows, post-processing (bloom, SSAO, SSR), custom shaders, instancing, LOD, physics, VR/XR. Actions: create, build, animate, render 3D scenes/models. Keywords: Three.js, WebGL, WebGPU, 3D graphics, scene, camera, geometry, material, light, animation, GLTF, FBX, OrbitControls, PBR, shadow mapping, post-processing, bloom, SSAO, shader, instancing, LOD, WebXR, VR, AR, product configurator, data visualization, architectural walkthrough, interactive 3D, canvas. Use when: creating 3D visualizations, building WebGL/WebGPU apps, loading 3D models, adding animations, implementing VR/XR, creating interactive graphics, building product configurators.