Skip to content
Tutorials Center
My learning

Topics

D3.js Tutorial

Learn D3.js step by step: 44 lessons in 9 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is D3.js? Learn what D3.js is, how it differs from charting libraries, how data, selections, scales and shapes fit together, and build your first chart in minutes.
  2. 2 Setting Up D3: CDN, ES Modules and npm Load D3.js with a script tag, as an ES module from a CDN or from npm, import only the modules you need, and set up a clean HTML page for your charts.
  3. 3 SVG Fundamentals for D3 Learn the SVG you need for D3: coordinate system, rect, circle, line, path and text, groups and transforms, the viewBox and the margin convention for charts.
  4. 4 Loading and Parsing Data in D3 Load CSV, TSV and JSON with d3.csv, d3.tsv and d3.json, parse text with csvParse, convert types with autoType, handle errors and async/await, and reshape rows.

Selections and Data Joins

  1. 5 Selecting Elements with d3.select Master D3 selections: select and selectAll, CSS selectors, attr, style, classed, text, html and property, method chaining.
  2. 6 Adding, Removing and Reordering Elements in D3 Create and remove DOM and SVG elements with D3: append, insert, remove, clone, raise, lower, order, sort, merge and join, plus when to use each method.
  3. 7 Binding Data to Elements in D3 Understand how selection.data() and datum() attach data to DOM elements, how the __data__ property works, what happens with more or fewer items.
  4. 8 Enter, Update and Exit: The General Update Pattern Learn the classic D3 data join with enter(), exit(), merge() and remove(): create elements for new data, update existing ones and remove leftovers.
  5. 9 The selection.join Method Use selection.join in D3 v7 to create, update and remove elements in one call, with function arguments for custom enter.
  6. 10 Nested Selections and Grouped Data Build tables and grouped marks with nested D3 selections: rows then cells, how data flows from parent to child, selectAll versus select, and parents and groups.
  7. 11 Data Utilities with d3-array Summarize and reshape data with d3-array: extent, min, max, sum, mean, median, quantile, group, rollup, bin, sort, range, cumsum, bisect and ticks.

Scales and Axes

  1. 12 Scales: Mapping Data to Pixels with scaleLinear Understand D3 scales: domain and range, scaleLinear, invert, clamp, nice, ticks, rounding, reversed ranges for the y axis.
  2. 13 Power, Log, Symlog and Time Scales in D3 Choose the right continuous D3 scale: scalePow and scaleSqrt for areas, scaleLog for wide ranges, scaleSymlog for zeros, scaleTime and scaleUtc for dates.
  3. 14 Band, Point and Ordinal Scales in D3 Position categories with scaleBand and scalePoint, control padding and bandwidth, and map categories to colors or shapes with scaleOrdinal.
  4. 15 Color Scales, Interpolators and Palettes in D3 Color data with D3: scaleSequential and interpolateViridis, diverging scales, quantize, quantile and threshold buckets, categorical schemes.
  5. 16 Axes in D3: Ticks, Labels and Gridlines Draw axes in D3 with axisBottom, axisLeft, axisTop and axisRight: set ticks, tickFormat and tickSize, add titles and gridlines, restyle with CSS.
  6. 17 Number and Time Formatting in D3 Format and parse values with d3.format specifiers (commas, SI prefixes, percent, currency), d3.timeFormat and utcFormat, d3.timeParse.

Shapes and Paths

  1. 18 Building Bar Charts with D3 Build a complete D3 bar chart step by step: margins, band and linear scales, axes, value labels, sorting.
  2. 19 Line Charts and Curves with d3.line Draw line charts with d3.line: time scales, accessors x and y, curve types, defined() for gaps, multiple series with grouping, dots.
  3. 20 Area, Stacked Bar and Stacked Area Charts in D3 Build area charts with d3.area, then stack series with d3.stack into stacked bars, stacked areas and streamgraphs using stack order and offset options.
  4. 21 Pie and Donut Charts with d3.pie and d3.arc Build pie, donut and radial charts with d3.pie and d3.arc: angles, innerRadius and outerRadius, padAngle, cornerRadius, centroid labels.
  5. 22 Scatter Plots, Bubble Charts and Symbols in D3 Build scatter plots and bubble charts in D3 with sqrt radius scales, d3.symbol shapes for categories, opacity and jitter against overplotting.
  6. 23 SVG Paths, d3.path, Links and Radial Shapes Read and write the SVG path mini-language (M, L, C, Q, A, Z), build paths with d3.path, draw connecting curves with d3.linkHorizontal and linkVertical.

Layouts and Hierarchies

  1. 24 Hierarchies and Tree Layouts Turn nested or flat data into a d3.hierarchy, walk it with descendants and links, and draw it as a tree or cluster diagram with d3.tree and d3.cluster.
  2. 25 Treemap, Partition and Pack Layouts Show hierarchical sizes with d3.treemap, d3.partition (icicle and sunburst) and d3.pack, including tiling methods, padding, colors and labels.
  3. 26 Force Simulations Learn how d3.forceSimulation works: many-body, center, collide, x/y and link forces, alpha cooling, tick events and how to draw simulated nodes.
  4. 27 Force-Directed Graphs Build a draggable force-directed network graph with d3.forceLink, node sizing by degree, colored groups, labels and hover highlighting of neighbors.
  5. 28 Chord Diagrams and Binning Draw relationships between groups with d3.chord and d3.ribbon, and group numbers into a histogram with d3.bin, thresholds and bar rendering.

Transitions and Interaction

  1. 29 Transitions Animate attribute and style changes with selection.transition(): duration, delay, chaining, named transitions, enter/exit animation in joins and events.
  2. 30 Easing and Interpolation Control the feel of a D3 animation with easing functions and build custom interpolators: numbers, colors, strings, transforms, attrTween and tweens.
  3. 31 Mouse Events and Tooltips Handle click, hover and touch in D3 with selection.on and d3.pointer, build HTML tooltips, highlight marks, and add a crosshair to a line chart with bisect.
  4. 32 Brushing, Zooming and Dragging Add d3.drag, d3.zoom and d3.brush to charts: draggable marks, pan and zoom with transforms, rescaling axes, brushing to select data and linked views.

Maps and Geo

  1. 33 Geographic Projections and Paths Draw maps with d3-geo: GeoJSON basics, projections (Mercator, Equal Earth, Orthographic), d3.geoPath, fitSize, graticules, centroids, circles and distances.
  2. 34 Choropleth and World Maps Load TopoJSON with topojson-client, draw a world map with d3.geoPath, join data to countries, color a choropleth with scales, add a legend and tooltips.
  3. 35 Zoomable and Interactive Maps Make D3 maps interactive: pan and zoom with d3.zoom, click-to-zoom on a region with fitExtent, hover highlighting, a draggable rotating globe and map performance tips.

Real-world Charts and Integration

  1. 36 Reusable Charts and Responsive Design Package D3 code as a reusable chart function with getters and setters, make SVG charts responsive with viewBox and ResizeObserver, and handle margins and updates.
  2. 37 Loading and Cleaning Data Load CSV and JSON with d3-fetch, convert types with autoType and row functions, parse dates, clean missing values, and summarize with group, rollup, sum and cumsum.
  3. 38 D3 with React, Vue and Other Frameworks Combine D3 with React, Vue or Svelte: let D3 own a DOM node via refs, or let the framework render and use D3 only for scales, shapes and layouts.
  4. 39 Canvas Rendering and Performance Render large D3 charts on canvas with shape generators and a 2D context, handle hover with quadtree search, mix SVG and canvas layers, and optimize performance.
  5. 40 Accessibility and Testing for D3 Charts Make D3 charts accessible with titles, ARIA roles, keyboard focus, data tables and color-safe palettes, and test chart code with unit tests of scales and DOM checks.

Projects and Practice

  1. 41 Project: An Interactive Sales Dashboard Build a small sales dashboard with D3: a daily line chart with a brush that filters a category bar chart and KPI numbers, built step by step in one reusable file.
  2. 42 Project: An Animated Bar Chart Race Build a bar chart race in D3: rank items per period, interpolate keyframes, animate sorted bars with transitions, add value labels, a ticking date and replay controls.
  3. 43 Project: A Drill-down Treemap with Breadcrumbs Build a clickable treemap that drills into categories with an animated zoom, shows a breadcrumb trail, tooltips and a color legend, using d3.hierarchy and d3.treemap.
  4. 44 Practice Exercises and Next Steps Test your D3 skills with self-checking exercises on scales, joins, layouts and shapes, a list of chart challenges with hints, common interview questions and what to learn next.