Skip to content

Instantly share code, notes, and snippets.

@seschultz
Last active November 3, 2017 02:35
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 seschultz/700db82b82d91e841c7413b006de311d to your computer and use it in GitHub Desktop.
Save seschultz/700db82b82d91e841c7413b006de311d to your computer and use it in GitHub Desktop.
project
license: mit
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>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/topojson.v2.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
// Feel free to change or delete any of the code you see in this editor!
/*var svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500)
svg.append("text")
.text("Edit the code below to change me!")
.attr("y", 200)
.attr("x", 120)
.attr("font-size", 36)
.attr("font-family", "monospace")*/
d3.json("Allegheny_County_Census_Tracts_2016.geojson", function(json){
// Loop through each state data value in the .csv file
for (var i = 0; i < data.length; i++) {
// Grab census tract
var dataState = data[i].censusTract;
// Grab data value
var dataValue = data[i].value;
// Find the corresponding state inside the GeoJSON
for (var j = 0; j < json.features.length; j++) {
var jsonState = json.features[j].properties.name;
if (dataState == jsonState) {
// Copy the data value into the JSON
json.features[j].properties.value = dataValue;
// Stop looking through the JSON
break;
}
}
}
})
// d3.queue()
// .defer(d3.json, "Allegheny_County_Census_Tracts_2016.geojson")
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment