Fireship · @fireship
D3.js in 100 Seconds
Uploaded September 21, 2021 · Length 2:20
Summary
learn d3.js library for interactive data visualizations in 100 seconds
- d3.js
- data visualization
- javascript library
- svg graphics
- web development
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
data driven documents or d3 is a
- 0:03
javascript library for creating
- 0:04
interactive data visualizations with
- 0:06
scalable vector graphics if you've ever
- 0:08
been to a website that has a graph map
- 0:11
scatter plot histogram dependency
- 0:12
diagram b swarm tree map or pie chart
- 0:15
it's probably powered by d3 under the
- 0:17
hood it was created in 2011 with the
- 0:19
goal of generating svg graphics from
- 0:22
data drawing a data visualization by
- 0:24
hand is extremely difficult with d3 you
- 0:26
start with some input data then write
- 0:28
some javascript to programmatically draw
- 0:30
the graphic for you which can then be
- 0:32
made interactive with things like labels
- 0:34
and controls and when the underlying
- 0:35
data changes it can interpolate and
- 0:37
animate between values resulting in a
- 0:40
beautiful visual for the end user that's
- 0:42
built entirely on web standards that you
- 0:43
already know like html css and
- 0:46
javascript its api allows you to select
- 0:48
and manipulate items in the dom not much
- 0:51
different than something like jquery
- 0:52
what makes d3 different is that you can
- 0:54
set properties as functions that
- 0:56
automatically draw different graphics
- 0:58
based on your data to get started you'll
- 1:00
first want to grab an element from the
- 1:02
dom with the select method like an empty
- 1:04
svg you could then draw a single shape
- 1:06
inside of it with the append method and
- 1:08
customize its appearance by chaining the
- 1:10
attribute method to it that draws a
- 1:12
single shape but the real power of d3
- 1:14
comes into play when you attach data to
- 1:16
a selection instead of using a for loop
- 1:18
to draw a bunch of shapes the select all
- 1:20
method allows you to describe how to
- 1:22
draw shape making your code more
- 1:24
declarative you can then attach data to
- 1:26
it in the form of an array or an
- 1:27
external file and it will draw a shape
- 1:29
for every point in your data set each
- 1:31
point has three possible states enter
- 1:34
update and exit enter is when you would
- 1:36
initially draw your shape but d3 also
- 1:38
keeps track of changes to the data set
- 1:40
allowing you to react when data is
- 1:42
updated or removed it also provides a
- 1:44
bunch of features to make your data look
- 1:46
beautiful like helpers that
- 1:47
automatically draw scales along the x
- 1:49
and y axis based on the domain and range
- 1:52
of the data or you might use transition
- 1:54
to create an animation as each data
- 1:56
point is added to the chart and finally
- 1:58
you might listen to events to add


