Fireship · @fireship

D3.js in 100 Seconds

Uploaded September 21, 2021 · Length 2:20

D3.js in 100 Seconds

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.

  1. 0:00

    data driven documents or d3 is a

  2. 0:03

    javascript library for creating

  3. 0:04

    interactive data visualizations with

  4. 0:06

    scalable vector graphics if you've ever

  5. 0:08

    been to a website that has a graph map

  6. 0:11

    scatter plot histogram dependency

  7. 0:12

    diagram b swarm tree map or pie chart

  8. 0:15

    it's probably powered by d3 under the

  9. 0:17

    hood it was created in 2011 with the

  10. 0:19

    goal of generating svg graphics from

  11. 0:22

    data drawing a data visualization by

  12. 0:24

    hand is extremely difficult with d3 you

  13. 0:26

    start with some input data then write

  14. 0:28

    some javascript to programmatically draw

  15. 0:30

    the graphic for you which can then be

  16. 0:32

    made interactive with things like labels

  17. 0:34

    and controls and when the underlying

  18. 0:35

    data changes it can interpolate and

  19. 0:37

    animate between values resulting in a

  20. 0:40

    beautiful visual for the end user that's

  21. 0:42

    built entirely on web standards that you

  22. 0:43

    already know like html css and

  23. 0:46

    javascript its api allows you to select

  24. 0:48

    and manipulate items in the dom not much

  25. 0:51

    different than something like jquery

  26. 0:52

    what makes d3 different is that you can

  27. 0:54

    set properties as functions that

  28. 0:56

    automatically draw different graphics

  29. 0:58

    based on your data to get started you'll

  30. 1:00

    first want to grab an element from the

  31. 1:02

    dom with the select method like an empty

  32. 1:04

    svg you could then draw a single shape

  33. 1:06

    inside of it with the append method and

  34. 1:08

    customize its appearance by chaining the

  35. 1:10

    attribute method to it that draws a

  36. 1:12

    single shape but the real power of d3

  37. 1:14

    comes into play when you attach data to

  38. 1:16

    a selection instead of using a for loop

  39. 1:18

    to draw a bunch of shapes the select all

  40. 1:20

    method allows you to describe how to

  41. 1:22

    draw shape making your code more

  42. 1:24

    declarative you can then attach data to

  43. 1:26

    it in the form of an array or an

  44. 1:27

    external file and it will draw a shape

  45. 1:29

    for every point in your data set each

  46. 1:31

    point has three possible states enter

  47. 1:34

    update and exit enter is when you would

  48. 1:36

    initially draw your shape but d3 also

  49. 1:38

    keeps track of changes to the data set

  50. 1:40

    allowing you to react when data is

  51. 1:42

    updated or removed it also provides a

  52. 1:44

    bunch of features to make your data look

  53. 1:46

    beautiful like helpers that

  54. 1:47

    automatically draw scales along the x

  55. 1:49

    and y axis based on the domain and range

  56. 1:52

    of the data or you might use transition

  57. 1:54

    to create an animation as each data

  58. 1:56

    point is added to the chart and finally

  59. 1:58

    you might listen to events to add