Skip to content

Instantly share code, notes, and snippets.

@emeeks
Created November 16, 2014 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emeeks/c531c16d64c17e3c41a3 to your computer and use it in GitHub Desktop.
Save emeeks/c531c16d64c17e3c41a3 to your computer and use it in GitHub Desktop.
Ch. 1, Fig. 27 - D3.js in Action

This is the code for Chapter 1, Figure 27 from D3.js in Action showing simple data binding using a filtered array filler data to create elements with content based on the values of the datapoints.

<html>
<head>
<title>D3 in Action Chapter 1 - Example 6</title>
<meta charset="utf-8" />
<script src="http://d3js.org/d3.v3.min.js" type="text/JavaScript"></script>
</head>
<style>
#vizcontainer {
width: 200px;
height: 100px;
border: 1px gray solid;
}
</style>
<body>
<div id="vizcontainer">
</div>
</body>
<footer>
<script>
var someNumbers = [17, 82, 9, 500, 40];
smallerNumbers = someNumbers.filter(function(el) {return el <= 40 ? this : null});
d3.select("body")
.selectAll("div")
.data(smallerNumbers)
.enter()
.append("div")
.html(function (d) {return d});
</script>
</footer>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment