Skip to content

Instantly share code, notes, and snippets.

@richschmitt
Last active October 19, 2017 14:57
Show Gist options
  • Save richschmitt/510ff7441f1549d989cfc54414b9bc16 to your computer and use it in GitHub Desktop.
Save richschmitt/510ff7441f1549d989cfc54414b9bc16 to your computer and use it in GitHub Desktop.
02_workshop_binding data to elements
license: mit
<!DOCTYPE html>
<head>
<title>d3js workshop - data binding</title>
<script src="http://d3js.org/d3.v3.js"></script> <!-- import D3 library -->
</head>
<body>
<script type="text/javascript">
// Write your code here
// an empty selection - looking for instantiations of data
names = d3.selectAll('div')
.data(['ben', 'elcin', 'ana', 'byron', 'jonatan'])
.enter()
.append('div')
names.text(function(d, i){return i +1 + " " +d;}); // let's really use the data to fill each element
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment