block by kenpenn b48f58ee59ba8088b5c58c2ecc33a8a9

d3 v4 set datum

Full Screen

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.

index.html