Last active
December 18, 2015 00:28
-
-
Save jmuyskens/5696641 to your computer and use it in GitHub Desktop.
randomly colored united states
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"> | |
</head> | |
<body> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://d3js.org/topojson.v0.min.js"></script> | |
<script src="random-color-states.js"></script> | |
</body> | |
</html> |
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
var width = 1160, | |
height = 960; | |
var projection = d3.geo.albersUsa() | |
var path = d3.geo.path() | |
.projection(projection) | |
.pointRadius(2); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
d3.json("usa.json", function(error, us) { | |
svg.selectAll(".state") | |
.data(topojson.object(us, us.objects.states).geometries) | |
.enter().append("path") | |
.attr("class", function(d) { return "state " + d.id; }) | |
.attr("d", path) | |
.style("fill", function() { | |
return "hsl(" + Math.random() * 360 + ",100%,50%)"; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment