Created
November 12, 2014 15:41
-
-
Save DavidChouinard/34aa03436546733a15e0 to your computer and use it in GitHub Desktop.
Act IV: Working with Data
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
[ | |
{"magnitude":5.1,"coordinates":[-71.120167,42.370580]}, | |
{"magnitude":2.73,"coordinates":[-119.6165,41.9069]}, | |
{"magnitude":3.35,"coordinates":[-124.9986649,40.409668]}, | |
{"magnitude":4.1,"coordinates":[-97.0925,36.0305]}, | |
{"magnitude":3.4,"coordinates":[-152.9566,59.0462]} | |
] |
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. | |
d3.json("data.json", function(data) { | |
var scale = d3.scale.linear() | |
.domain([1,10]) | |
.range([20,width-40]); | |
var circles = svg.selectAll("circle") | |
.data(data) | |
.enter().append("circle"); | |
circles | |
.attr("cx", function(d,i) { | |
return scale(d.magnitude); | |
}) | |
.attr("cy", 200) | |
.attr("r", 40) | |
.style("fill", "steelblue") | |
.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