Skip to content

Instantly share code, notes, and snippets.

@Andrew-Reid
Created March 6, 2017 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andrew-Reid/198dc6efa1160dc3302ad2908b7d3296 to your computer and use it in GitHub Desktop.
Save Andrew-Reid/198dc6efa1160dc3302ad2908b7d3296 to your computer and use it in GitHub Desktop.
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.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
</style>
<body>
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="https://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 500,
height = 500;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var color = d3.scale.category20();
var projection = d3.geo.albers()
.center([0,40.7])
.rotate([74,0])
.translate([width/2,height/2])
.scale(65000);
var path = d3.geo.path()
.projection(projection);
d3.json("ct2010.json", function(error, data) {
if (error) return console.error(error);
svg.selectAll(".tract")
.data(topojson.feature(data, data.objects.nyct2010).features)
.enter().append("path")
.attr('class','tract')
.attr('fill',function(d,i) { return color(i); })
.attr("d", path);
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment