Created
November 12, 2014 15:32
-
-
Save DavidChouinard/365a78eb0f6a505c5cd9 to your computer and use it in GitHub Desktop.
Act II: Data-driven documents
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
// You'll generally need a local server for requests to work. Run: | |
// python -m SimpleHTTPServer | |
var width = 700, | |
height = 500; | |
var svg = d3.select("svg") | |
.attr("width", width) | |
.attr("height", height); | |
// The code aboves sets up the basic SVG element required for | |
// drawing vector graphics in the browser. Real code starts below. | |
var data = [10, 45, 105, 69, 80, 55, 200]; | |
var circles = svg.selectAll("circle") | |
.data(data) | |
.enter().append("circle") | |
circles | |
.attr("cx", function(d,i) { | |
return d * 3 + 20; | |
}) | |
.attr("cy", 200) | |
.attr("r", 40) | |
.style("fill", function(d,i) { | |
if (d < 50) | |
return "green"; | |
else | |
return "red"; | |
}) | |
.style("fill-opacity", 0.5); |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>Data Visualization and D3</title> | |
<meta content="David Chouinard" name="author" /> | |
<style type="text/css"> | |
html, body { | |
margin: 0; | |
padding: 0; | |
} | |
</style> | |
</head> | |
<body> | |
<svg></svg> | |
</body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="demo.js"></script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment