Skip to content

Instantly share code, notes, and snippets.

@matthieu-foucault
Last active February 22, 2018 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthieu-foucault/1b3afc8c32d9fc177a091d05dfa93237 to your computer and use it in GitHub Desktop.
Save matthieu-foucault/1b3afc8c32d9fc177a091d05dfa93237 to your computer and use it in GitHub Desktop.
d3.js tutorial - Infoviz course @UVic

Getting started with d3.js

Matthieu Foucault (mfoucault@uvic.ca) - Feb, 22, 2018

Useful links

What does D3 do?

  1. Makes it easier to manipulate (create, update, delete) HTML and SVG elements
  2. Provides a scales modules: really helpful to transform arbitrary scales into pixels.
  3. Modules that help with manipulating data (Hierarchies, Forces, Voronoi)

Where to start?

⚠️ There are two main versions of d3.js that are used online (v3 and v4). They are not compatible, so make sure you are using the right one (v4 is preferred)

  1. Go to blockbuilder.org and edit existing examples
  1. Look at the API to see all the things d3 can do

Gotchas

  • The y axis (with SVG or Canvas) goes from top to bottom, which is why a vertical scale's range will often be [height, 0] instead of [0, height]
  • Many d3 functions are factory methods: they return the function that you need to pass your data to. E.g. d3.scaleLinear() returns the scale function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment