Skip to content

Instantly share code, notes, and snippets.

@dmachat
Last active August 29, 2015 14:24
Show Gist options
  • Save dmachat/ff5ebd3be950d377586e to your computer and use it in GitHub Desktop.
Save dmachat/ff5ebd3be950d377586e to your computer and use it in GitHub Desktop.
Datamaps with U.S. Counties
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="http://rawgithub.com/markmarkoh/datamaps/master/dist/datamaps.none.min.js"></script>
<div id="counties" style="height: 500px; width: 900px;"></div>
<script>
var map = new Datamap({
element: document.getElementById('counties'),
geographyConfig: {
dataUrl: 'us.json'
},
scope: 'counties',
setProjection: function(element, options) {
var projection, path;
projection = d3.geo.albersUsa()
.scale(element.offsetWidth)
.translate([element.offsetWidth / 2, element.offsetHeight / 2 ]);
path = d3.geo.path()
.projection( projection );
return {path: path, projection: projection};
}
});
</script>
</body>
</html>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment