Skip to content

什么是 D3?

¥What is D3?

D3(或 D3.js)是一个免费的开源 JavaScript 数据可视化库。它基于 Web 标准构建的底层方法为创作动态数据驱动的图形提供了无与伦比的灵活性。十多年来,D3 一直致力于推动突破性且屡获殊荣的可视化成果,成为高级图表库的基础构建块,并在全球范围内培育了一个充满活力的数据从业者社区。

¥D3 (or D3.js) is a free, open-source JavaScript library for visualizing data. Its low-level approach built on web standards offers unparalleled flexibility in authoring dynamic, data-driven graphics. For more than a decade D3 has powered groundbreaking and award-winning visualizations, become a foundational building block of higher-level chart libraries, and fostered a vibrant community of data practitioners around the world.

D3“推动了该字段的增长、多样化和创造力,这是前所未有的”,并且“改变了新闻编辑室、网站和个人作品集中数百万个数据可视化作品的创建方式”,《信息之美》2022 时间考验奖 如此评价。IEEE VIS 2021 时间考验奖 指出:“通过创建一个引人注目且易于 Web 开发者用来创作交互式可视化的框架,作者们无疑为数据可视化进入主流做出了贡献。”[D3] 是本次会议的基石性贡献,尤其对我们整个字段的成功至关重要。

¥D3 “slingshotted the field into growth, diversification and creativity that has been unprecedented” and “changed how millions of data visualizations are created across newsrooms, websites, and personal portfolios,” remarked the Information is Beautiful 2022 Test of Time Award. The IEEE VIS 2021 Test of Time Award noted, “By creating a framework that was compelling and easy for web developers to use to author interactive visualizations, the authors have undeniably helped to bring data visualization to the mainstream. [D3] is a cornerstone contribution to this conference specifically and more generally to the success of our field as a whole.”

D3 由 Mike Bostock 于 2011 年创建。Mike 与斯坦福大学的 Jeff Heer 和 Vadim Ogievetsky 共同编写了 D3 论文。Jason Davies 在 2011 年至 2013 年间为 D3 做出了重大贡献,其中最突出的是 D3 的地理投影系统。Philippe Rivière 自 2016 年以来一直是 D3 及其文档的主要贡献者。多年来,无数善良的人们通过分享代码和想法、教学和解答问题以及将人们聚集在一起以进一步推动可视化实践,为 D3 做出了贡献。Mike 和 Philippe 现在在 Observable 维护 D3 和 Observable Plot

¥D3 was created by Mike Bostock in 2011. Mike co-authored the D3 paper with Jeff Heer and Vadim Ogievetsky at Stanford. Jason Davies made major contributions to D3 from 2011 to 2013, most notably to D3’s geographic projection system. Philippe Rivière has been a major contributor to D3 and its documentation since 2016. Over the years, countless kind individuals have contributed to D3 by sharing code and ideas, by teaching and answering questions, and by bringing people together to further the practice of visualization. Mike and Philippe now maintain D3 and Observable Plot at Observable.

D3 是一个低级工具箱

¥D3 is a low-level toolbox

D3 并非传统意义上的图表库。它没有“图表”的概念。使用 D3 可视化数据时,你会组合各种基元。

¥D3 is not a charting library in the traditional sense. It has no concept of “charts”. When you visualize data with D3, you compose a variety of primitives.

要创建 堆叠面积图,你可以使用

¥To make a stacked area chart, you might use

这很难理解,对吧?但请深呼吸 - 你不必一次性学习所有内容。每个部分都可以独立使用,因此你可以在将它们组合在一起之前分别学习它们。D3 并非单一的整体式架构,而是一套由 30 个独立的库(或“模块”)组成的套件。我们将这些模块打包在一起是为了方便使用,而非必要,以便你在迭代设计时可以使用这些工具。

¥That’s a lot to take in, right? But take a deep breath — you don’t have to learn everything at once. Each piece can be used independently, so you can learn them individually before you fit them together. D3 is not a single monolith but rather a suite of 30 discrete libraries (or “modules”). We bundle these modules together for convenience rather than necessity so your tools are within reach as you iterate on your design.

D3 工具箱里都有什么?我们建议你浏览文档和示例,以了解与你相关的内容。

¥What all’s in the D3 toolbox? We recommend exploring the documentation and examples to get a sense of what’s relevant to you.

/D3/D3/简介/D3/可视化/D3/动画/D3/交互/D3/数据/D3/简介/什么是 D3?/D3/简介/什么是 D3?/D3/简介/入门/D3/简介/入门/D3/简介/API 索引/D3/简介/API 索引/D3/简介/示例/D3/简介/示例/D3/可视化/d3-axis/D3/可视化/d3-axis/D3/可视化/d3-chord/D3/可视化/d3-chord/D3/可视化/d3-color/D3/可视化/d3-color/D3/可视化/d3-interpolate/D3/可视化/d3-interpolate/D3/可视化/d3-contour/D3/可视化/d3-contour/D3/可视化/d3-delaunay/D3/可视化/d3-delaunay/D3/可视化/d3-force/D3/可视化/d3-force/D3/可视化/d3-geo/D3/可视化/d3-geo/D3/可视化/d3-hierarchy/D3/可视化/d3-hierarchy/D3/可视化/d3-path/D3/可视化/d3-path/D3/可视化/d3-polygon/D3/可视化/d3-polygon/D3/可视化/d3-quadtree/D3/可视化/d3-quadtree/D3/可视化/d3-scale/D3/可视化/d3-scale/D3/可视化/d3-scale-chromatic/D3/可视化/d3-scale-chromatic/D3/可视化/d3-selection/D3/可视化/d3-selection/D3/可视化/d3-shape/D3/可视化/d3-shape/D3/动画/d3-ease/D3/动画/d3-ease/D3/动画/d3-timer/D3/动画/d3-timer/D3/动画/d3-transition/D3/动画/d3-transition/D3/交互/d3-brush/D3/交互/d3-brush/D3/交互/d3-dispatch/D3/交互/d3-dispatch/D3/交互/d3-drag/D3/交互/d3-drag/D3/交互/d3-zoom/D3/交互/d3-zoom/D3/数据/d3-array/D3/数据/d3-array/D3/数据/d3-dsv/D3/数据/d3-dsv/D3/数据/d3-fetch/D3/数据/d3-fetch/D3/数据/d3-format/D3/数据/d3-format/D3/数据/d3-random/D3/数据/d3-random/D3/数据/d3-time/D3/数据/d3-time/D3/数据/d3-time-format/D3/数据/d3-time-format/D3/可视化/d3-chord/弦/D3/可视化/d3-chord/弦/D3/可视化/d3-chord/色带/D3/可视化/d3-chord/色带/D3/可视化/d3-interpolate/值插值/D3/可视化/d3-interpolate/值插值/D3/可视化/d3-interpolate/颜色插值/D3/可视化/d3-interpolate/颜色插值/D3/可视化/d3-interpolate/变换插值/D3/可视化/d3-interpolate/变换插值/D3/可视化/d3-interpolate/缩放插值/D3/可视化/d3-interpolate/缩放插值/D3/可视化/d3-contour/轮廓多边形/D3/可视化/d3-contour/轮廓多边形/D3/可视化/d3-contour/密度估计/D3/可视化/d3-contour/密度估计/D3/可视化/d3-delaunay/Delaunay 三角剖分/D3/可视化/d3-delaunay/Delaunay 三角剖分/D3/可视化/d3-delaunay/Voronoi 图/D3/可视化/d3-delaunay/Voronoi 图/D3/可视化/d3-force/力模拟/D3/可视化/d3-force/力模拟/D3/可视化/d3-force/中心力/D3/可视化/d3-force/中心力/D3/可视化/d3-force/碰撞力/D3/可视化/d3-force/碰撞力/D3/可视化/d3-force/连接力/D3/可视化/d3-force/连接力/D3/可视化/d3-force/多体力/D3/可视化/d3-force/多体力/D3/可视化/d3-force/位置力/D3/可视化/d3-force/位置力/D3/可视化/d3-geo/路径/D3/可视化/d3-geo/路径/D3/可视化/d3-geo/投影/D3/可视化/d3-geo/投影/D3/可视化/d3-geo/流/D3/可视化/d3-geo/流/D3/可视化/d3-geo/球面形状/D3/可视化/d3-geo/球面形状/D3/可视化/d3-geo/球面数学/D3/可视化/d3-geo/球面数学/D3/可视化/d3-hierarchy/层级结构/D3/可视化/d3-hierarchy/层级结构/D3/可视化/d3-hierarchy/分层/D3/可视化/d3-hierarchy/分层/D3/可视化/d3-hierarchy/树/D3/可视化/d3-hierarchy/树/D3/可视化/d3-hierarchy/簇/D3/可视化/d3-hierarchy/簇/D3/可视化/d3-hierarchy/分区/D3/可视化/d3-hierarchy/分区/D3/可视化/d3-hierarchy/打包/D3/可视化/d3-hierarchy/打包/D3/可视化/d3-hierarchy/树形图/D3/可视化/d3-hierarchy/树形图/D3/可视化/d3-scale/线性尺度/D3/可视化/d3-scale/线性尺度/D3/可视化/d3-scale/时间尺度/D3/可视化/d3-scale/时间尺度/D3/可视化/d3-scale/功率尺度/D3/可视化/d3-scale/功率尺度/D3/可视化/d3-scale/对数尺度/D3/可视化/d3-scale/对数尺度/D3/可视化/d3-scale/Symlog 尺度/D3/可视化/d3-scale/Symlog 尺度/D3/可视化/d3-scale/序数尺度/D3/可视化/d3-scale/序数尺度/D3/可视化/d3-scale/带尺度/D3/可视化/d3-scale/带尺度/D3/可视化/d3-scale/点尺度/D3/可视化/d3-scale/点尺度/D3/可视化/d3-scale/顺序尺度/D3/可视化/d3-scale/顺序尺度/D3/可视化/d3-scale/发散尺度/D3/可视化/d3-scale/发散尺度/D3/可视化/d3-scale/分位数尺度/D3/可视化/d3-scale/分位数尺度/D3/可视化/d3-scale/量化尺度/D3/可视化/d3-scale/量化尺度/D3/可视化/d3-scale/阈值尺度/D3/可视化/d3-scale/阈值尺度/D3/可视化/d3-scale-chromatic/分类方案/D3/可视化/d3-scale-chromatic/分类方案/D3/可视化/d3-scale-chromatic/循环方案/D3/可视化/d3-scale-chromatic/循环方案/D3/可视化/d3-scale-chromatic/发散方案/D3/可视化/d3-scale-chromatic/发散方案/D3/可视化/d3-scale-chromatic/顺序方案/D3/可视化/d3-scale-chromatic/顺序方案/D3/可视化/d3-selection/选择元素/D3/可视化/d3-selection/选择元素/D3/可视化/d3-selection/修改元素/D3/可视化/d3-selection/修改元素/D3/可视化/d3-selection/连接数据/D3/可视化/d3-selection/连接数据/D3/可视化/d3-selection/处理事件/D3/可视化/d3-selection/处理事件/D3/可视化/d3-selection/控制流/D3/可视化/d3-selection/控制流/D3/可视化/d3-selection/局部变量/D3/可视化/d3-selection/局部变量/D3/可视化/d3-selection/命名空间/D3/可视化/d3-selection/命名空间/D3/可视化/d3-shape/圆弧/D3/可视化/d3-shape/圆弧/D3/可视化/d3-shape/区域/D3/可视化/d3-shape/区域/D3/可视化/d3-shape/曲线/D3/可视化/d3-shape/曲线/D3/可视化/d3-shape/直线/D3/可视化/d3-shape/直线/D3/可视化/d3-shape/链接/D3/可视化/d3-shape/链接/D3/可视化/d3-shape/饼图/D3/可视化/d3-shape/饼图/D3/可视化/d3-shape/堆栈/D3/可视化/d3-shape/堆栈/D3/可视化/d3-shape/符号/D3/可视化/d3-shape/符号/D3/可视化/d3-shape/径向区域/D3/可视化/d3-shape/径向区域/D3/可视化/d3-shape/径向线/D3/可视化/d3-shape/径向线/D3/可视化/d3-shape/径向链接/D3/可视化/d3-shape/径向链接/D3/动画/d3-transition/选择元素/D3/动画/d3-transition/选择元素/D3/动画/d3-transition/修改元素/D3/动画/d3-transition/修改元素/D3/动画/d3-transition/时序/D3/动画/d3-transition/时序/D3/动画/d3-transition/控制流/D3/动画/d3-transition/控制流/D3/数据/d3-array/数字相加/D3/数据/d3-array/数字相加/D3/数据/d3-array/数据分箱/D3/数据/d3-array/数据分箱/D3/数据/d3-array/数据二等分/D3/数据/d3-array/数据二等分/D3/数据/d3-array/数据模糊/D3/数据/d3-array/数据模糊/D3/数据/d3-array/数据分组/D3/数据/d3-array/数据分组/D3/数据/d3-array/驻留值/D3/数据/d3-array/驻留值/D3/数据/d3-array/集合运算/D3/数据/d3-array/集合运算/D3/数据/d3-array/数据排序/D3/数据/d3-array/数据排序/D3/数据/d3-array/数据汇总/D3/数据/d3-array/数据汇总/D3/数据/d3-array/刻度/D3/数据/d3-array/刻度/D3/数据/d3-array/数据变换/D3/数据/d3-array/数据变换/D3/可视化/d3-geo/投影/方位投影/D3/可视化/d3-geo/投影/方位投影/D3/可视化/d3-geo/投影/圆锥投影/D3/可视化/d3-geo/投影/圆锥投影/D3/可视化/d3-geo/投影/圆柱投影/D3/可视化/d3-geo/投影/圆柱投影什么是 D3?/D3/简介/什么是 D3?什么是 D3?/D3/简介/什么是 D3?入门/D3/简介/入门入门/D3/简介/入门API 索引/D3/简介/API 索引API 索引/D3/简介/API 索引示例/D3/简介/示例示例/D3/简介/示例d3-axis/D3/可视化/d3-axisd3-axis/D3/可视化/d3-axisd3-color/D3/可视化/d3-colord3-color/D3/可视化/d3-colord3-path/D3/可视化/d3-pathd3-path/D3/可视化/d3-pathd3-polygon/D3/可视化/d3-polygond3-polygon/D3/可视化/d3-polygond3-quadtree/D3/可视化/d3-quadtreed3-quadtree/D3/可视化/d3-quadtreed3-ease/D3/动画/d3-eased3-ease/D3/动画/d3-eased3-timer/D3/动画/d3-timerd3-timer/D3/动画/d3-timerd3-brush/D3/交互/d3-brushd3-brush/D3/交互/d3-brushd3-dispatch/D3/交互/d3-dispatchd3-dispatch/D3/交互/d3-dispatchd3-drag/D3/交互/d3-dragd3-drag/D3/交互/d3-dragd3-zoom/D3/交互/d3-zoomd3-zoom/D3/交互/d3-zoomd3-dsv/D3/数据/d3-dsvd3-dsv/D3/数据/d3-dsvd3-fetch/D3/数据/d3-fetchd3-fetch/D3/数据/d3-fetchd3-format/D3/数据/d3-formatd3-format/D3/数据/d3-formatd3-random/D3/数据/d3-randomd3-random/D3/数据/d3-randomd3-time/D3/数据/d3-timed3-time/D3/数据/d3-timed3-time-format/D3/数据/d3-time-formatd3-time-format/D3/数据/d3-time-format/D3/可视化/d3-chord/弦/D3/可视化/d3-chord/弦色带/D3/可视化/d3-chord/色带色带/D3/可视化/d3-chord/色带值插值/D3/可视化/d3-interpolate/值插值值插值/D3/可视化/d3-interpolate/值插值颜色插值/D3/可视化/d3-interpolate/颜色插值颜色插值/D3/可视化/d3-interpolate/颜色插值变换插值/D3/可视化/d3-interpolate/变换插值变换插值/D3/可视化/d3-interpolate/变换插值缩放插值/D3/可视化/d3-interpolate/缩放插值缩放插值/D3/可视化/d3-interpolate/缩放插值轮廓多边形/D3/可视化/d3-contour/轮廓多边形轮廓多边形/D3/可视化/d3-contour/轮廓多边形密度估计/D3/可视化/d3-contour/密度估计密度估计/D3/可视化/d3-contour/密度估计Delaunay 三角剖分/D3/可视化/d3-delaunay/Delaunay 三角剖分Delaunay 三角剖分/D3/可视化/d3-delaunay/Delaunay 三角剖分Voronoi 图/D3/可视化/d3-delaunay/Voronoi 图Voronoi 图/D3/可视化/d3-delaunay/Voronoi 图力模拟/D3/可视化/d3-force/力模拟力模拟/D3/可视化/d3-force/力模拟中心力/D3/可视化/d3-force/中心力中心力/D3/可视化/d3-force/中心力碰撞力/D3/可视化/d3-force/碰撞力碰撞力/D3/可视化/d3-force/碰撞力连接力/D3/可视化/d3-force/连接力连接力/D3/可视化/d3-force/连接力多体力/D3/可视化/d3-force/多体力多体力/D3/可视化/d3-force/多体力位置力/D3/可视化/d3-force/位置力位置力/D3/可视化/d3-force/位置力路径/D3/可视化/d3-geo/路径路径/D3/可视化/d3-geo/路径/D3/可视化/d3-geo/流/D3/可视化/d3-geo/流球面形状/D3/可视化/d3-geo/球面形状球面形状/D3/可视化/d3-geo/球面形状球面数学/D3/可视化/d3-geo/球面数学球面数学/D3/可视化/d3-geo/球面数学层级结构/D3/可视化/d3-hierarchy/层级结构层级结构/D3/可视化/d3-hierarchy/层级结构分层/D3/可视化/d3-hierarchy/分层分层/D3/可视化/d3-hierarchy/分层/D3/可视化/d3-hierarchy/树/D3/可视化/d3-hierarchy/树/D3/可视化/d3-hierarchy/簇/D3/可视化/d3-hierarchy/簇分区/D3/可视化/d3-hierarchy/分区分区/D3/可视化/d3-hierarchy/分区打包/D3/可视化/d3-hierarchy/打包打包/D3/可视化/d3-hierarchy/打包树形图/D3/可视化/d3-hierarchy/树形图树形图/D3/可视化/d3-hierarchy/树形图线性尺度/D3/可视化/d3-scale/线性尺度线性尺度/D3/可视化/d3-scale/线性尺度时间尺度/D3/可视化/d3-scale/时间尺度时间尺度/D3/可视化/d3-scale/时间尺度功率尺度/D3/可视化/d3-scale/功率尺度功率尺度/D3/可视化/d3-scale/功率尺度对数尺度/D3/可视化/d3-scale/对数尺度对数尺度/D3/可视化/d3-scale/对数尺度Symlog 尺度/D3/可视化/d3-scale/Symlog 尺度Symlog 尺度/D3/可视化/d3-scale/Symlog 尺度序数尺度/D3/可视化/d3-scale/序数尺度序数尺度/D3/可视化/d3-scale/序数尺度带尺度/D3/可视化/d3-scale/带尺度带尺度/D3/可视化/d3-scale/带尺度点尺度/D3/可视化/d3-scale/点尺度点尺度/D3/可视化/d3-scale/点尺度顺序尺度/D3/可视化/d3-scale/顺序尺度顺序尺度/D3/可视化/d3-scale/顺序尺度发散尺度/D3/可视化/d3-scale/发散尺度发散尺度/D3/可视化/d3-scale/发散尺度分位数尺度/D3/可视化/d3-scale/分位数尺度分位数尺度/D3/可视化/d3-scale/分位数尺度量化尺度/D3/可视化/d3-scale/量化尺度量化尺度/D3/可视化/d3-scale/量化尺度阈值尺度/D3/可视化/d3-scale/阈值尺度阈值尺度/D3/可视化/d3-scale/阈值尺度分类方案/D3/可视化/d3-scale-chromatic/分类方案分类方案/D3/可视化/d3-scale-chromatic/分类方案循环方案/D3/可视化/d3-scale-chromatic/循环方案循环方案/D3/可视化/d3-scale-chromatic/循环方案发散方案/D3/可视化/d3-scale-chromatic/发散方案发散方案/D3/可视化/d3-scale-chromatic/发散方案顺序方案/D3/可视化/d3-scale-chromatic/顺序方案顺序方案/D3/可视化/d3-scale-chromatic/顺序方案选择元素/D3/可视化/d3-selection/选择元素选择元素/D3/可视化/d3-selection/选择元素修改元素/D3/可视化/d3-selection/修改元素修改元素/D3/可视化/d3-selection/修改元素连接数据/D3/可视化/d3-selection/连接数据连接数据/D3/可视化/d3-selection/连接数据处理事件/D3/可视化/d3-selection/处理事件处理事件/D3/可视化/d3-selection/处理事件控制流/D3/可视化/d3-selection/控制流控制流/D3/可视化/d3-selection/控制流局部变量/D3/可视化/d3-selection/局部变量局部变量/D3/可视化/d3-selection/局部变量命名空间/D3/可视化/d3-selection/命名空间命名空间/D3/可视化/d3-selection/命名空间圆弧/D3/可视化/d3-shape/圆弧圆弧/D3/可视化/d3-shape/圆弧区域/D3/可视化/d3-shape/区域区域/D3/可视化/d3-shape/区域曲线/D3/可视化/d3-shape/曲线曲线/D3/可视化/d3-shape/曲线直线/D3/可视化/d3-shape/直线直线/D3/可视化/d3-shape/直线链接/D3/可视化/d3-shape/链接链接/D3/可视化/d3-shape/链接饼图/D3/可视化/d3-shape/饼图饼图/D3/可视化/d3-shape/饼图堆栈/D3/可视化/d3-shape/堆栈堆栈/D3/可视化/d3-shape/堆栈符号/D3/可视化/d3-shape/符号符号/D3/可视化/d3-shape/符号径向区域/D3/可视化/d3-shape/径向区域径向区域/D3/可视化/d3-shape/径向区域径向线/D3/可视化/d3-shape/径向线径向线/D3/可视化/d3-shape/径向线径向链接/D3/可视化/d3-shape/径向链接径向链接/D3/可视化/d3-shape/径向链接选择元素/D3/动画/d3-transition/选择元素选择元素/D3/动画/d3-transition/选择元素修改元素/D3/动画/d3-transition/修改元素修改元素/D3/动画/d3-transition/修改元素时序/D3/动画/d3-transition/时序时序/D3/动画/d3-transition/时序控制流/D3/动画/d3-transition/控制流控制流/D3/动画/d3-transition/控制流数字相加/D3/数据/d3-array/数字相加数字相加/D3/数据/d3-array/数字相加数据分箱/D3/数据/d3-array/数据分箱数据分箱/D3/数据/d3-array/数据分箱数据二等分/D3/数据/d3-array/数据二等分数据二等分/D3/数据/d3-array/数据二等分数据模糊/D3/数据/d3-array/数据模糊数据模糊/D3/数据/d3-array/数据模糊数据分组/D3/数据/d3-array/数据分组数据分组/D3/数据/d3-array/数据分组驻留值/D3/数据/d3-array/驻留值驻留值/D3/数据/d3-array/驻留值集合运算/D3/数据/d3-array/集合运算集合运算/D3/数据/d3-array/集合运算数据排序/D3/数据/d3-array/数据排序数据排序/D3/数据/d3-array/数据排序数据汇总/D3/数据/d3-array/数据汇总数据汇总/D3/数据/d3-array/数据汇总刻度/D3/数据/d3-array/刻度刻度/D3/数据/d3-array/刻度数据变换/D3/数据/d3-array/数据变换数据变换/D3/数据/d3-array/数据变换方位投影/D3/可视化/d3-geo/投影/方位投影方位投影/D3/可视化/d3-geo/投影/方位投影圆锥投影/D3/可视化/d3-geo/投影/圆锥投影圆锥投影/D3/可视化/d3-geo/投影/圆锥投影圆柱投影/D3/可视化/d3-geo/投影/圆柱投影圆柱投影/D3/可视化/d3-geo/投影/圆柱投影D3/D3简介/D3/简介可视化/D3/可视化动画/D3/动画交互/D3/交互数据/D3/数据d3-chord/D3/可视化/d3-chordd3-chord/D3/可视化/d3-chordd3-interpolate/D3/可视化/d3-interpolated3-interpolate/D3/可视化/d3-interpolated3-contour/D3/可视化/d3-contourd3-contour/D3/可视化/d3-contourd3-delaunay/D3/可视化/d3-delaunayd3-delaunay/D3/可视化/d3-delaunayd3-force/D3/可视化/d3-forced3-force/D3/可视化/d3-forced3-geo/D3/可视化/d3-geod3-geo/D3/可视化/d3-geod3-hierarchy/D3/可视化/d3-hierarchyd3-hierarchy/D3/可视化/d3-hierarchyd3-scale/D3/可视化/d3-scaled3-scale/D3/可视化/d3-scaled3-scale-chromatic/D3/可视化/d3-scale-chromaticd3-scale-chromatic/D3/可视化/d3-scale-chromaticd3-selection/D3/可视化/d3-selectiond3-selection/D3/可视化/d3-selectiond3-shape/D3/可视化/d3-shaped3-shape/D3/可视化/d3-shaped3-transition/D3/动画/d3-transitiond3-transition/D3/动画/d3-transitiond3-array/D3/数据/d3-arrayd3-array/D3/数据/d3-array投影/D3/可视化/d3-geo/投影投影/D3/可视化/d3-geo/投影

提示

Unless you need D3’s low-level control, we recommend our high-level sister library:Observable Plot。D3 中的直方图可能需要 50 行代码,而 Plot 只需一行代码即可完成!Plot 简洁而富有表现力的 API 让你可以更专注于数据分析和可视化,而不是 Web 开发。你甚至可以将 Plot 和 D3 结合使用,以获得两者的最佳效果。

¥Unless you need D3’s low-level control, we recommend our high-level sister library: Observable Plot. Whereas a histogram in D3 might require 50 lines of code, Plot can do it in one! Plot’s concise yet expressive API lets you focus more on analyzing and visualizing data instead of web development. You can even combine Plot and D3 for the best of both.

D3 非常灵活

¥D3 is flexible

由于 D3 没有总体的“图表”抽象,即使是一个基本的图表也可能需要几十行代码。好处是,所有部分都摆放在你面前,你可以完全控制后续操作。你可以定制可视化效果,以精确实现你的需求。D3 没有默认的数据呈现方式 - 只有你自己编写的代码。(或从示例中复制。)

¥Because D3 has no overarching “chart” abstraction, even a basic chart may require a few dozen lines of code. On the upside, all the pieces are laid out in front of you and you have complete control over what happens. You can tailor the visualization to achieve exactly what you want. D3 has no default presentation of your data — there’s just the code you write yourself. (Or copy from an example.)

将 D3 视为“自己动手”的替代方案,而不是高级图表库的替代方案。如果你对其他工具不满意,并且正在考虑使用 SVG 或 Canvas(甚至 WebGL)制作自己的图表,那么你不妨仔细阅读 D3 的工具箱!这里几乎肯定有一些东西可以帮助你构建梦想中的图表,而不会影响你的创造力。

¥Consider D3 an alternative to “doing everything yourself”, not an alternative to a high-level charting library. If you aren’t satisfied with other tools and you’re thinking of rolling your own charts using SVG or Canvas (or even WebGL), you might as well peruse D3’s toolbox! There’s almost certainly something here that will help you build the chart of your dreams without imposing on your creativity.

D3 可与 Web 配合使用

¥D3 works with the web

D3 不会引入新的图形表示形式;你可以将 D3 直接与 SVG 和 Canvas 等 Web 标准结合使用。

¥D3 doesn’t introduce a new graphical representation; instead, you use D3 directly with web standards such as SVG and Canvas.

“D3”是数据驱动文档 (data-driven documents) 的缩写,其中 documents 指的是代表网页内容的 文档对象模型 (DOM) 标准。虽然 D3 的一些模块(例如 selectionstransitions)会接触 DOM,但其他​​模块(包括 scalesshapes)仅对数据进行操作。D3 还可以与 React、Vue 和 Svelte 等 Web 框架配对使用;请参阅 入门指南 中的建议。

¥The name “D3” is short for data-driven documents, where documents refers to the Document Object Model (DOM) standard that represents the contents of a webpage. While some of D3’s modules (such as selections and transitions) touch the DOM, others (including scales and shapes) only operate on data. D3 can also be paired with web frameworks such as React, Vue, and Svelte; see the getting started guide for recommendations.

D3 对 Web 标准的采用带来了诸多好处。例如,你可以使用外部样式表来更改图表的外观(即使是为了响应媒体查询,例如响应式图表或暗黑模式);你可以使用调试器和元素检查器来检查代码的运行情况;D3 的同步、命令式求值模型 - 调用 selection.attr 会立即改变 DOM - 比那些具有复杂异步运行时的框架更容易调试。

¥D3’s embrace of web standards brings many benefits. For example, you can use external stylesheets to alter the appearance of charts (even in response to media queries, say for responsive charts or dark mode); you can use the debugger and element inspector to review what your code is doing; and D3’s synchronous, imperative evaluation model — calling selection.attr immediately mutates the DOM — can make it easier to debug than frameworks with complex asynchronous runtimes.

D3 用于定制可视化

¥D3 is for bespoke visualization

D3 让一切成为可能,但并不一定容易;即使是简单的事情,本应很容易,但往往并非如此。套用 Amanda Cox 的话:“如果你认为为条形图编写一百行代码很正常,请使用 D3。”

¥D3 makes things possible, not necessarily easy; even simple things that should be easy are often not. To paraphrase Amanda Cox: “Use D3 if you think it’s perfectly normal to write a hundred lines of code for a bar chart.”

如果你需要为你的定制可视化提供极致的表现力,则应该考虑使用 D3。D3 对于像《纽约时报》或 The Pudding 这样的媒体机构来说意义非凡,因为在这些机构中,一张图片可能会被数百万读者看到,并且编辑团队可以齐心协力,共同推动视觉传播字段的发展。

¥If you need maximal expressiveness for your bespoke visualization, you should consider D3. D3 makes sense for media organizations such as The New York Times or The Pudding, where a single graphic may be seen by a million readers, and where a team of editors can work together to advance the state of the art in visual communication.

另一方面,D3 对于拼凑私有仪表板或一次性分析来说有些过度了。不要被那些炫酷的例子所迷惑:其中许多方法的实现都花费了巨大的精力!如果你时间紧迫(谁没有时间呢?),使用 Observable Plot 可能会产生更好的可视化或分析效果。

¥On the other hand, D3 is overkill for throwing together a private dashboard or a one-off analysis. Don’t get seduced by whizbang examples: many of them took an immense effort to implement! If you’re constrained by time (and who isn’t?), you’d likely produce a better visualization or analysis with Observable Plot.

D3 用于动态可视化

¥D3 is for dynamic visualization

D3 最新颖的概念是它的 数据连接:给定一组数据和一组 DOM 元素,数据连接允许你对元素的输入、更新和退出应用单独的操作。如果你只创建静态图表(不带动画或不响应用户输入的图表),你可能会觉得这个概念不直观,甚至很奇怪,因为它根本不需要。

¥D3’s most novel concept is its data join: given a set of data and a set of DOM elements, the data join allows you to apply separate operations for entering, updating, and exiting elements. If you’re only creating static charts (charts that don’t animate or respond to user input), you may find this concept unintuitive or even bizarre because it’s not needed.

数据连接的存在是为了让你能够精确控制数据更改时发生的情况,并相应地更新显示。这种直接控制可以实现极高的更新性能 - 你只需修改需要更改的元素和属性,而无需对 DOM 进行 diff 操作 - 并实现状态间流畅的动画过渡。D3 在动态交互式可视化方面表现出色。(尝试在 2012 年的 “通往白宫的 512 条路径” 中按住 Option 键并单击状态切换按钮。真的。)

¥The data join exists so that you can control exactly what happens when your data changes and update the display in response. This direct control allows extremely performant updates — you only touch the elements and attributes that need changing, without diffing the DOM — and smooth animated transitions between states. D3 shines for dynamic, interactive visualizations. (Try option-clicking the state toggles in “512 Paths to the White House” from 2012. Really.)