Skip to content

Instantly share code, notes, and snippets.

@hoschi
Created September 9, 2013 13:59
Show Gist options
  • Save hoschi/6495952 to your computer and use it in GitHub Desktop.
Save hoschi/6495952 to your computer and use it in GitHub Desktop.
testing data join 'states' with deep selection
<!DOCTYPE html>
<meta charset="utf-8">
<style>
</style>
<body>
<script src="http://d3js.org/d3.v3.js"></script>
<script>
function chartIt(data) {
var main = d3.select('body').selectAll("div").data(data);
// update
main.select('p').style('color', 'red');
// enter
var mainEnter = main.enter();
mainEnter.append('div').append('p');
// enter + update
main.select('p').text(function(d){return d;})
};
var data = ['foo', 'bar']
chartIt(data);
setTimeout(function () {
data = ['lol', 'olo'];
chartIt(data);
}, 800);
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment