Built with blockbuilder.org
xxxxxxxxxx
<meta charset="utf-8">
<style type="text/css">
body {
font-family: arial, sans;
font-size: 14px;
width: 960px;
margin: 40px auto;
}
svg {
border: 1px solid #ccc;
}
.states {
stroke:#fff;
fill:none;
}
.counties {
stroke: #fff;
fill: green;
stroke-width: .3px;
}
.county-bubble {
stroke:#fff;
stroke-width: .3;
}
</style>
<body>
</body>
<script src="https://d3js.org/d3.v4.js" charset="utf-8"></script>
<script src="https://d3js.org/topojson.v1.min.js"></script>
<script type="text/javascript">
var width = 960,
height = 500;
var color = d3.scaleLinear()
.range(["#d73027","#fc8d59","#fee08b","#ffffbf","#d9ef8b","#91cf60","#1a9850"])
.domain([10,9,8,7,6,5,4,3]);
var radius = d3.scaleSqrt()
.range([0,20])
.domain([0,500000]);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.queue()
.defer(d3.tsv, "infantMortalityState.txt")
.defer(d3.json, "us.json")
.await(ready);
function ready(error, deaths, us) {
if (error) return console.warn(error);
console.log(deaths);
console.log(us);
console.log(topojson.feature(us, us.objects.states).features);
deathsByFips = {};
deaths.forEach(function(d) {
d.Deaths = +d.Deaths;
d["Death Rate"] = +d["Death Rate"];
deathsByFips[+d["State Code"]] = d;
});
var path = d3.geoPath()
.projection(d3.geoAlbersUsa());
var subset = topojson.feature(us, us.objects.states).features.filter(function(d) {
return d.id in deathsByFips;
});
svg.append("g")
.attr("class", "counties")
.selectAll("path")
.data(subset)
.enter().append("path")
.attr("d", path)
.style("fill", function(d) {
return color(deathsByFips[d.id]["Death Rate"])
});
svg.append("path")
.datum(topojson.mesh(us, us.objects.states, function(a, b) { return a.id !== b.id; }))
.attr("class", "states")
.attr("d", path);
}
</script>
Modified http://d3js.org/d3.v4.js to a secure url
Modified http://d3js.org/topojson.v1.min.js to a secure url
https://d3js.org/d3.v4.js
https://d3js.org/topojson.v1.min.js