Skip to content

Instantly share code, notes, and snippets.

@Treblesteph
Created November 7, 2015 12:15
Show Gist options
  • Save Treblesteph/aa2cbc009e4e6964f2cb to your computer and use it in GitHub Desktop.
Save Treblesteph/aa2cbc009e4e6964f2cb to your computer and use it in GitHub Desktop.
d3intro_ex00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Mozfest example</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
.existing {color: blue;}
.new {color: green;}
</style>
</head>
<body>
<h1>Mozfest: D3 intro</h1>
<!--<p> previous paragraph</p>-->
<script type="text/javascript">
test = [1,2,3];
// We make a DOM selection using D3 and link data to it
var p = d3.select("body").selectAll("p").data(test);
// Update subselection
p.attr("class",function(d,i) {return "existing";});
// Enter subselection
p.enter()
.append("p")
.text(function(d,i) {return "The value is "+d;})
.attr("class","new");
// Exit subselection
p.exit().remove();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment