Skip to content

Instantly share code, notes, and snippets.

Forked from mbostock/.block
Last active March 8, 2017 11:39
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Area Choropleth
license: gpl-3.0

This choropleth encodes the area of each county using color on a log scale from red to blue.

<!DOCTYPE html>
<meta charset="utf-8">
.states {
fill: none;
stroke: #fff;
stroke-linejoin: round;
<script src="//"></script>
<script src="//"></script>
var width = 960,
height = 500;
var fill = d3.scale.log()
.domain([10, 500])
.range(["brown", "steelblue"]);
var path = d3.geo.path();
var svg ="body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("/mbostock/raw/4090846/us.json", function(error, us) {
if (error) throw error;
.attr("class", "counties")
.data(topojson.feature(us, us.objects.counties).features)
.attr("d", path)
.style("fill", function(d) { return fill(path.area(d)); });
.datum(topojson.mesh(us, us.objects.states, function(a, b) { return !==; }))
.attr("class", "states")
.attr("d", path);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment