Skip to content

Instantly share code, notes, and snippets.

@micahasmith
Created December 17, 2011 21:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micahasmith/1491435 to your computer and use it in GitHub Desktop.
Save micahasmith/1491435 to your computer and use it in GitHub Desktop.
d3.js enter example
//so there's two divs on the page for this to select
d3.select('body')
.selectAll('div')
.data(["hello","there","world"])
//this will map "hello" and "there" to the only two divs
.html(function(d){return d;})
//but theres 3 pieces of data...?
//this is why d3 has the enter() function
//think of it as "withTheLeftOverDataAfterMapping()" instead of "enter()"
.enter()
//so now we can do something with the leftover data,
//how about create another div?
.append('div')
.html(function(d){return d;});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment