Skip to main content
skill CX Codex

d3js-visualization — Claude Code skill: D3 charts, install

d3js-visualization teaches the agent to write D3.js charts: bars, lines, pies, tooltips, zoom. Useful when the visual has to be coded rather than pulled from a chart library.

MIT 189 installs ★ 9 updated 2026-10-25

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add Bbeierle12/Skill-MCP-Claude --skill d3js-visualization -a claude-code
Open on GitHub

What d3js-visualization does

The skill is a reference the agent reads before writing chart code. It covers binding arrays to DOM nodes, picking a scale for the job (linear, band, time, ordinal colour), and attaching axes to an SVG group. Three functions come ready: createBarChart, createLineChart and createPieChart, each taking data, a container and an options object for size and margins.

Interaction has its own section. A tooltip is a div appended to body that follows the pointer on mousemove. Transitions run on data updates, with an optional delay per index. Zoom uses scaleExtent([1, 8]). The closing notes are about speed and access: aria-label on the SVG, role="img" on decorative charts, a data table beside the picture.

Date strings in the samples go through d3.timeParse('%Y-%m-%d'), so a different format needs that line changed. And innerRadius starts at 0, which draws a pie; raise it and you get a donut.

What it helps with

  • draw a bar chart from an array of objects
  • make a tooltip follow the cursor
  • animate a chart when the data changes
  • add zoom and pan to a line chart
  • label an SVG so a screen reader can read it

Example prompts for the agent

  • Build a bar chart of monthly revenue in D3.js from sales.json
  • Add a tooltip and a smooth transition to the line chart
  • Turn the pie into a donut with innerRadius 60

How to install d3js-visualization

1Skills CLI (Vercel)

npx skills add Bbeierle12/Skill-MCP-Claude --skill d3js-visualization -a claude-code

2Manually: put the files in place

~/.claude/skills/d3js-visualization/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/d3js-visualization/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about d3js-visualization

How do I install d3js-visualization in Claude Code?

Run npx skills add Bbeierle12/Skill-MCP-Claude --skill d3js-visualization -a claude-code. The skill file lands at ~/.claude/skills/d3js-visualization/SKILL.md.

What does d3js-visualization do?

It hands the agent D3.js building blocks: binding data to elements, scales, axes, bar, line and pie charts, tooltips and zoom.

Does it work in Cursor, Codex or GitHub Copilot?

Yes. Cursor and Codex use the same npx skills add command with -a cursor or -a codex; for GitHub Copilot run gh skill install Bbeierle12/Skill-MCP-Claude d3js-visualization.

Source text

SKILL.md · MIT
---
name: d3js-visualization
description: Create D3.js charts and interactive data visualizations. Use when building bar charts, line charts, scatter plots, pie charts, force-directed graphs, geographic maps, or any custom data visualization.
---

# D3.js Visualization

## Core Concepts

### Selection and Data Binding
```javascript
// Select elements
const svg = d3.select('#chart')
  .append('svg')
  .attr('width', width)
  .attr('height', height);

// Bind data to elements
svg.selectAll('rect')
  .data(data)
  .join('rect')
  .attr('x', (d, i) => i * barWidth)
  .attr('y', d => height - scale(d.value))
  .attr('width', barWidth - 1)
  .attr('height', d => scale(d.value));
```

### Scales
```javascript
// Linear scale (continuous → continuous)
const xScale = d3.scaleLinear()
  .domain([0, d3.max(data, d => d.value)])
  .range([0, width]);

// Band scale (discrete → continuous)
const xScale = d3.scaleBand()
  .domain(data.map(d => d.name))
  .range([0, width])
  .padding(0.1);

// Time scale
const xScale = d3.scaleTime()
  .domain([startDate, endDate])
  .range([0, width]);

// Color scale
const colorScale = d3.scaleOrdinal(d3.schemeCategory10);
```

### Axes
```javascript
// Create axes
const xAxis = d3.axisBottom(xScale);
const yAxis = d3.axisLeft(yScale);

// Append to SVG
svg.append('g')
  .attr('class', 'x-axis')
  .attr('transform', `translate(0, ${height})`)
  .call(xAxis);

svg.append('g')
  .attr('class', 'y-axis')
  .call(yAxis);
```

## Common Chart Types

### Bar Chart
```javascript
function createBarChart(data, container, options = {}) {
  const {
    width = 600,
    height = 400,
    margin = { top: 20, right: 20, bottom: 30, left: 40 }
  } = options;

  const innerWidth = width - margin.left - margin.right;
  const innerHeight = height - margin.top - margin.bottom;

  const svg = d3.select(container)
    .append('svg')
    .attr('width', width)
    .attr('height', height);

  const g = svg.append('g')
    .attr('transform', `translate(${margin.left},${margin.top})`);

  const xScale = d3.scaleBand()
    .domain(data.map(d => d.name))
    .range([0, innerWidth])
    .padding(0.1);

  const yScale = d3.scaleLinear()
    .domain([0, d3.max(data, d => d.value)])
    .nice()
    .range([innerHeight, 0]);

  // Bars
  g.selectAll('.bar')
    .data(data)
    .join('rect')
    .attr('class', 'bar')
    .attr('x', d => xScale(d.name))
    .attr('y', d => yScale(d.value))
    .attr('width', xScale.bandwidth())
    .attr('height', d => innerHeight - yScale(d.value))
    .attr('fill', 'steelblue');

  // Axes
  g.append('g')
    .attr('transform', `translate(0,${innerHeight})`)
    .call(d3.axisBottom(xScale));

  g.append('g')
    .call(d3.axisLeft(yScale));

  return svg.node();
}
```

### Line Chart
```javascript
function createLineChart(data, container, options = {}) {
  const {
    width = 600,
    height = 400,
    margin = { top: 20, right: 20, bottom: 30, left: 40 }
  } = options;

  const innerWidth = width - margin.left - margin.right;
  const innerHeight = height - margin.top - margin.bottom;

  const svg = d3.select(container)
    .append('svg')
    .attr('width', width)
    .attr('height', height);

  const g = svg.append('g')
    .attr('transform', `translate(${margin.left},${margin.top})`);

  const xScale = d3.scaleTime()
    .domain(d3.extent(data, d => d.date))
    .range([0, innerWidth]);

  const yScale = d3.scaleLinear()
    .domain([0, d3.max(data, d => d.value)])
    .nice()
    .range([innerHeight, 0]);

  // Line generator
  const line = d3.line()
    .x(d => xScale(d.date))
    .y(d => yScale(d.value))
    .curve(d3.curveMonotoneX);

  // Path
  g.append('path')
    .datum(data)
    .attr('fill', 'none')
    .attr('stroke', 'steelblue')
    .attr('stroke-width', 2)
    .attr('d', line);

  // Dots
  g.selectAll('.dot')
    .data(data)
    .join('circle')
    .attr('class', 'dot')
    .attr('cx', d => xScale(d.date))
    .attr('cy', d => yScale(d.value))
    .attr('r', 4)
    .attr('fill', 'steelblue');

  // Axes
  g.append('g')
    .attr('transform', `translate(0,${innerHeight})`)
    .call(d3.axisBottom(xScale));

  g.append('g')
    .call(d3.axisLeft(yScale));

  return svg.node();
}
```

### Pie/Donut Chart
```javascript
function createPieChart(data, container, options = {}) {
  const {
    width = 400,
    height = 400,
    innerRadius = 0, // 0 for pie, > 0 for donut
  } = options;

  const radius = Math.min(width, height) / 2;

  const svg = d3.select(container)
    .append('svg')
    .attr('width', width)
    .attr('height', height);

  const g = svg.append('g')
    .attr('transform', `translate(${width / 2},${height / 2})`);

  const color = d3.scaleOrdinal(d3.schemeCategory10);

  const pie = d3.pie()
    .value(d => d.value)
    .sort(null);

  const arc = d3.arc()
    .innerRadius(innerRadius)
    .outerRadius(radius - 10);

  const arcs = g.selectAll('.arc')
    .data(pie(data))
    .join('g')
    .attr('class', 'arc');

  arcs.append('path')
    .attr('d', arc)
    .attr('fill', d => color(d.data.name));

  arcs.append('text')
    .attr('transform', d => `translate(${arc.centroid(d)})`)
    .attr('text-anchor', 'middle')
    .text(d => d.data.name);

  return svg.node();
}
```

## Interactivity

### Tooltips
```javascript
// Create tooltip
const tooltip = d3.select('body')
  .append('div')
  .attr('class', 'tooltip')
  .style('position', 'absolute')
  .style('visibility', 'hidden')
  .style('background', 'white')
  .style('padding', '10px')
  .style('border-radius', '4px')
  .style('box-shadow', '0 2px 4px rgba(0,0,0,0.2)');

// Add to elements
bars.on('mouseover', function(event, d) {
    tooltip
      .style('visibility', 'visible')
      .html(`<strong>${d.name}</strong><br/>Value: ${d.value}`);
  })
  .on('mousemove', function(event) {
    tooltip
      .style('top', (event.pageY - 10) + 'px')
      .style('left', (event.pageX + 10) + 'px');
  })
  .on('mouseout', function() {
    tooltip.style('visibility', 'hidden');
  });
```

### Transitions
```javascript
// Animate on data update
bars.transition()
  .duration(750)
  .attr('y', d => yScale(d.value))
  .attr('height', d => innerHeight - yScale(d.value));

// Staggered animation
bars.transition()
  .delay((d, i) => i * 50)
  .duration(500)
  .attr('opacity', 1);
```

### Zoom and Pan
```javascript
const zoom = d3.zoom()
  .scaleExtent([1, 8])
  .on('zoom', (event) => {
    g.attr('transform', event.transform);
  });

svg.call(zoom);
```

## Best Practices

### Performance
- Use `join()` instead of enter/update/exit for cleaner code
- Throttle resize handlers
- Use CSS for simple styling
- Avoid excessive DOM updates

### Accessibility
- Add `aria-label` to SVG
- Use `role="img"` for decorative charts
- Provide data tables as alternatives
- Ensure sufficient color contrast

### Data Formatting
```javascript
// Parse dates
const parseDate = d3.timeParse('%Y-%m-%d');
data.forEach(d => {
  d.date = parseDate(d.dateString);
});

// Format numbers
const formatNumber = d3.format(',.0f');
const formatCurrency = d3.format('$,.2f');
const formatPercent = d3.format('.1%');
```

© Bbeierle12 · MIT · Bbeierle12/Skill-MCP-Claude

Similar skills

All skills for Frontend and UI →

From the same set19

The whole set →
gsap-scrolltrigger A skill for GSAP ScrollTrigger: tie animations to scroll position, pin sections, build parallax and snap points. Useful when a page has to react to scrolling. CX Codex +1 612installs gsap-fundamentals gsap-fundamentals is a Claude Code skill covering GSAP tweens, timelines, easing, and animation properties. It explains adding motion to UI elements and getting started with GSAP. CX Codex +1 286installs shader-effects This skill provides GLSL patterns for glow, distortion, grain, glitch, and other shader effects. Use it for post-processing or stylized rendering. CX Codex +1 225installs frontend-dev-guidelines frontend-dev-guidelines — a convention set for React and TypeScript work: folder layout, data loading, styling and tests. It loads when the agent touches frontend code. CX Codex +1 105installs particles-gpu particles-gpu generates GPU-accelerated particle systems for Three.js and React Three Fiber. Ideal for rendering thousands to millions of points smoothly. CX Codex +1 173installs shader-fundamentals The shader-fundamentals skill covers GLSL basics, from vertex and fragment shaders to coordinates, types, and data flow. Use it when building or debugging shader code. CX Codex +1 173installs gsap-sequencing The gsap-sequencing skill guides complex GSAP timelines with labels, nested sequences, callbacks, and precise placement. Use it for coordinated UI motion. CX Codex +1 163installs audio-analysis audio-analysis is a Claude Code skill for inspecting audio with Tone.js and the Web Audio API. It supports work on visualizations, beat detection, and audio-reactive features. CX Codex +1 151installs

Project sponsors

Companies that keep this analytics open