Token导航 LogoToken导航TokenDH.com
前端设计操作浏览器github未标认证来源可访问clear审计通过

d3js-visualizationd3js 可视化

Agent Skill

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。它适合让 Agent 生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码,整理组件结构,或定位布局和性能问题。使用时需要结合项目现有设计系统、路由和构建方式,避免只生成孤立片段;涉及页面改动时,应配合本地预览和构建检查确认视觉效果。

总安装

461

周安装

19

GitHub Stars

9

下载量

150
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:d3js-visualization(d3js 可视化)
来源仓库:https://github.com/autumnsgrove/claudeskills
仓库路径:skills/d3js-visualization
安装命令:
npx skills add https://github.com/autumnsgrove/claudeskills --skill d3js-visualization
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/autumnsgrove/claudeskills --skill d3js-visualization

简介

d3js-visualization 指导使用 D3.js 创建动态交互图表,适合需要精细控制与自定义可视化的场景。

  • 适用于非标准图表类型、复杂动画或大数据集 Canvas 渲染。
  • 支持 SVG/HTML/CSS 绑定数据变换,兼容 Web 标准。
  • 使用前需准备数据结构与 DOM 容器,避免依赖第三方图表库。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

D3.js Data Visualization Skill

What is D3.js

D3.js (Data-Driven Documents) is a JavaScript library for producing dynamic, interactive data visualizations in web browsers. It uses HTML, SVG, and CSS standards to bind data to the DOM and apply data-driven transformations.

When to Use D3.js

Choose D3.js when you need:

  • Custom, unique visualizations not available in chart libraries
  • Fine-grained control over every visual element
  • Complex interactions and animations
  • Data-driven DOM manipulation beyond just charts
  • Performance with large datasets (when using Canvas)
  • Web standards-based visualizations

Consider alternatives when:

  • Simple standard charts are sufficient (use Chart.js, Plotly)
  • Quick prototyping is priority (use Observable, Vega-Lite)
  • Static charts for print/reports (use matplotlib, ggplot2)
  • 3D visualizations (use Three.js, WebGL libraries)

D3.js vs Other Libraries

LibraryBest ForLearning CurveCustomization
D3.jsCustom visualizationsSteepComplete
Chart.jsStandard chartsEasyLimited
PlotlyScientific plotsMediumGood
HighchartsBusiness dashboardsEasyGood
Three.js3D graphicsSteepComplete

Core Workflow

1. Project Setup

Option 1: CDN (Quick Start)

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>D3 Visualization</title>
  <style>
    body { margin: 0; font-family: sans-serif; }
    svg { display: block; }
  </style>
</head>
<body>
  <div id="chart"></div>
  <script src="https://d3js.org/d3.v7.min.js"></script>
  <script>
    // Your code here
  </script>
</body>
</html>

Option 2: NPM (Production)

npm install d3
// Import all of D3
import * as d3 from "d3";

// Or import specific modules
import { select, selectAll } from "d3-selection";
import { scaleLinear, scaleTime } from "d3-scale";

2. Create Basic Chart

// Set up dimensions and margins
const margin = {top: 20, right: 30, bottom: 40, left: 50};
const width = 800 - margin.left - margin.right;
const height = 400 - margin.top - margin.bottom;

// Create SVG
const svg = d3.select("#chart")
  .append("svg")
  .attr("width", width + margin.left + margin.right)
  .attr("height", height + margin.top + margin.bottom)
  .append("g")
  .attr("transform", `translate(${margin.left},${margin.top})`);

// Load and process data
d3.csv("data.csv", d => ({
  date: new Date(d.date),
  value: +d.value
})).then(data => {

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

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

  // Create and append axes
  svg.append("g")
    .attr("transform", `translate(0,${height})`)
    .call(d3.axisBottom(xScale));

  svg.append("g")
    .call(d3.axisLeft(yScale));

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

  // Draw line
  svg.append("path")
    .datum(data)
    .attr("d", line)
    .attr("fill", "none")
    .attr("stroke", "steelblue")
    .attr("stroke-width", 2);
});

3. Add Interactivity

Tooltips:

const tooltip = d3.select("body")
  .append("div")
  .attr("class", "tooltip")
  .style("position", "absolute")
  .style("visibility", "hidden")
  .style("background", "white")
  .style("border", "1px solid #ddd")
  .style("padding", "10px")
  .style("border-radius", "4px");

circles
  .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:

circles
  .transition()
  .duration(300)
  .ease(d3.easeCubicOut)
  .attr("r", 8);

4. Implement Responsive Design

function createChart() {
  const container = d3.select("#chart");
  const containerWidth = container.node().getBoundingClientRect().width;

  const margin = {top: 20, right: 30, bottom: 40, left: 50};
  const width = containerWidth - margin.left - margin.right;
  const height = Math.min(width * 0.6, 500);

  container.selectAll("*").remove(); // Clear previous

  // Create SVG...
}

// Initial render
createChart();

// Re-render on resize with debouncing
let resizeTimer;
window.addEventListener("resize", () => {
  clearTimeout(resizeTimer);
  resizeTimer = setTimeout(createChart, 250);
});

Key Principles

Data Binding

  • Use .data() to bind data to DOM elements
  • Handle enter, update, and exit selections
  • Use key functions for consistent element-to-data matching
  • Modern syntax: use .join() for cleaner code

Scales

  • Map data values (domain) to visual values (range)
  • Use appropriate scale types (linear, time, band, ordinal)
  • Apply .nice() to scales for rounded axis values
  • Invert y-scale range for bottom-up coordinates: [height, 0]

SVG Coordinate System

  • Origin (0,0) is at top-left corner
  • Y increases downward (opposite of Cartesian)
  • Use margin convention for proper spacing
  • Group related elements with <g> tags

Performance

  • Use SVG for <1,000 elements
  • Use Canvas for >1,000 elements
  • Aggregate or sample large datasets
  • Debounce resize handlers

Chart Selection Guide

Time series data? → Line chart or area chart

Comparing categories? → Bar chart (vertical or horizontal)

Showing relationships? → Scatter plot or bubble chart

Part-to-whole? → Donut chart or stacked bar (limit to 5-7 categories)

Network data? → Force-directed graph

Distribution? → Histogram or box plot

See references/chart-types.md for detailed chart selection criteria and best practices.


Common Patterns

Quick Data Loading

// Load CSV with type conversion
d3.csv("data.csv", d => ({
  date: new Date(d.date),
  value: +d.value,
  category: d.category
})).then(data => {
  createChart(data);
});

Quick Tooltip

selection
  .on("mouseover", (event, d) => {
    tooltip.style("visibility", "visible").html(`Value: ${d.value}`);
  })
  .on("mousemove", (event) => {
    tooltip.style("top", event.pageY + "px").style("left", event.pageX + "px");
  })
  .on("mouseout", () => tooltip.style("visibility", "hidden"));

Quick Responsive SVG

svg
  .attr("viewBox", `0 0 ${width} ${height}`)
  .attr("preserveAspectRatio", "xMidYMid meet")
  .style("width", "100%")
  .style("height", "auto");

Quality Standards

Visual Quality

  • Use appropriate chart type for data
  • Apply consistent color schemes
  • Include clear axis labels and legends
  • Provide proper spacing with margin convention
  • Use appropriate scale types and ranges

Interaction Quality

  • Add meaningful tooltips
  • Use smooth transitions (300-500ms duration)
  • Provide hover feedback
  • Enable keyboard navigation for accessibility
  • Implement zoom/pan for detailed exploration

Code Quality

  • Use key functions in data joins
  • Handle enter, update, and exit properly
  • Clean up previous renders before updates
  • Use reusable chart pattern for modularity
  • Debounce expensive operations

Accessibility

  • Add ARIA labels and descriptions
  • Provide keyboard navigation
  • Use colorblind-safe palettes
  • Include text alternatives for screen readers
  • Ensure sufficient color contrast

Helper Resources

Available Scripts

  • data-helpers.js: Data loading, parsing, and transformation utilities
  • chart-templates.js: Reusable chart templates for common visualizations

See scripts/ directory for implementations.

Working Examples

  • line-chart.html: Time series visualization with tooltips
  • bar-chart.html: Grouped and stacked bar charts
  • network-graph.html: Force-directed network visualization

See examples/ directory for complete implementations.

Detailed References


Troubleshooting

Chart not appearing?

  • Check browser console for errors
  • Verify data loaded correctly
  • Ensure SVG has width and height
  • Check scale domains and ranges

Elements in wrong position?

  • Verify scale domain matches data range
  • Check if y-scale range is inverted: [height, 0]
  • Confirm margin transform applied to <g> element
  • Check SVG coordinate system (top-left origin)

Transitions not working?

  • Ensure duration is reasonable (300-500ms)
  • Check if transition applied to selection, not data
  • Verify easing function is valid
  • Confirm elements exist before transitioning

Poor performance?

  • Reduce number of DOM elements (use Canvas if >1,000)
  • Aggregate or sample data
  • Debounce resize handlers
  • Minimize redraws

External Resources

Official Documentation

Learning Resources

Color Tools

Inspiration


This skill provides comprehensive coverage of D3.js for creating professional, interactive data visualizations. Use the core workflow as a starting point, refer to the detailed references for specific topics, and customize the examples for your needs.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Cursor

27.21%
按下载量换算41

Codex

24.52%
按下载量换算37

windsurf

18.28%
按下载量换算27

OpenCode

11.35%
按下载量换算17

weavefox

7.93%
按下载量换算12

Claude Code

3.38%
按下载量换算5

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills