This is the code for Chapter 4, Figure 3 from D3.js in Action showing how to create a simple scatterplot.
Last active
March 18, 2016 04:57
-
-
Save emeeks/54eb70e68989e5d25c51 to your computer and use it in GitHub Desktop.
Ch. 4, Fig. 3 - 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 4 - Example 1</title> | |
<meta charset="utf-8" /> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
</head> | |
<style> | |
svg { | |
height: 500px; | |
width: 500px; | |
border: 1px solid gray; | |
} | |
</style> | |
<body> | |
<div id="viz"> | |
<svg> | |
</svg> | |
</div> | |
</body> | |
<footer> | |
<script> | |
var scatterData = [{friends: 5, salary: 22000}, {friends: 3, salary: 18000}, {friends: 10, salary: 88000}, {friends: 0, salary: 180000}, {friends: 27, salary: 56000}, {friends: 8, salary: 74000}] | |
d3.select("svg") | |
.selectAll("circle") | |
.data(scatterData) | |
.enter() | |
.append("circle") | |
.attr("r", 5) | |
.attr("cx", function(d,i) {return i * 10}) | |
.attr("cy", function(d) {return d.friends}); | |
</script> | |
</footer> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment