All examples By author By category About

kenpenn

d3 v4 set datum

Using d3 v4 to set and use .datum() on elements

With d3 v3, when you set .datum() on an element created from blah.selectAll("blahblah").enter(),

the datum is bound to the element, and can be used later.

With d3 v4, when you set .datum() on an element created from blah.selectAll("blahblah").enter(),

the element is bound to the .data() of the .enter(), and any .datum() you set cannot be used later,

unless you create a new selection that's not bound to the data.

Clicking the right button will toggle between the d3 v3 way of setting datum and the d3 v4 way.

The difference is that the d3 v4 way requires an extra circleG.selectAll('circle')

Compare this example to d3 v3 set datum.