Last active
November 21, 2015 01:11
-
-
Save asuozzo/3fac07bcf4846cb29fb3 to your computer and use it in GitHub Desktop.
d3 map of the USA
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> | |
<meta charset="utf-8"> | |
<title>USA Map</title> | |
<style> | |
body { | |
margin: 0; | |
background-color: rgb(0, 9, 129); | |
font-family: serif; | |
} | |
h1 { | |
margin-top:0px; | |
margin-bottom:5px; | |
} | |
#container { | |
width: 950px; | |
margin-left: auto; | |
margin-right: auto; | |
margin-top: 50px; | |
padding: 50px; | |
background-color: rgb(245, 216, 174); | |
box-shadow: 3px 3px 5px 5px rgb(4, 11, 103); | |
} | |
svg path { | |
fill:rgb(0, 9, 129); | |
} | |
</style> | |
<body> | |
<script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script> | |
<div id="container"> | |
<h1>The United States of America</h1> | |
<div id="map"></div></div> | |
<script> | |
var w = 900, | |
h = 500; | |
var projection = d3.geo.albersUsa() | |
.scale(900); | |
var path = d3.geo.path() | |
.projection(projection) | |
var svg = d3.select("#map") | |
.append("svg") | |
.attr("width", w) | |
.attr("height", h); | |
d3.json("states.json", function(error, states) { | |
if (error) return console.error(error); | |
svg.selectAll("path") | |
.data(states.features) | |
.enter() | |
.append("path") | |
.attr("d", path); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment