Intro to D3.js



Intro to D3.js

0 10


d3intro

Intro to D3.js

On Github sxywu / d3intro

Intro to D3.js

Shirley Wu (@shirleyxywu)

Data-Driven Documents

D3.js manipulates documents by binding data to them.

Selections

select selectAll

d3.select("tr")
body
tr
tr
tr
d3.selectAll("tr")
body
tr
tr
tr

under da hood

*dotted lines indicate parentNode

d3.select("tr")
d3.selectAll("tr")
d3.selectAll("tr").selectAll("td")
body
tr
td
td
tr
td
td
d3.selectAll("tr").style("color", "red")
body
tr
tr
tr

data

datum data

d3.select("tr").datum([1, 2, 3])
body
tr [1, 2, 3]
tr
tr
d3.selectAll("tr").data([1, 2, 3])
body
tr 1
tr 2
tr 3

enter

update

exit

d3.selectAll("tr").data([1, 2, 3, 4, 5])
body
tr 1
tr 2
tr 3
But where's 4 and 5?
d3.selectAll("tr").data([1, 2, 3, 4, 5]).enter() d3.selectAll("tr").data([1, 2, 3, 4, 5]).enter().append("tr")
d3.selectAll("tr").data([4, 5]).exit() d3.selectAll("tr").data([4, 5]).enter().remove()

let's go through an example

Radial Reingold–Tilford Tree

some great resources

How Selections WorkThree Little Circles