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.
Created
November 16, 2014 17:29
-
-
Save emeeks/c531c16d64c17e3c41a3 to your computer and use it in GitHub Desktop.
Ch. 1, Fig. 27 - D3.js in Action
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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