Second part of the spam.js choropleth tutorial.
Creating a linear scale with ColorBrewer colors, filling the polygons with the scale according to the data.
license: mit | |
border: none | |
height: 1096 |
Second part of the spam.js choropleth tutorial.
Creating a linear scale with ColorBrewer colors, filling the polygons with the scale according to the data.
<!DOCTYPE html> | |
<meta charset="utf-8" /> | |
<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 src="https://unpkg.com/rbush@1.4.3/rbush.js"></script> | |
<script src="https://unpkg.com/spamjs@1.1.0/spam.min.js"></script> | |
<script type='text/javascript'> | |
var color = d3.scale | |
.linear() | |
.domain([0.1, 0.18, 0.26, 0.33, 0.41]) | |
.range(["#ca0020", "#f4a582", "#f7f7f7", "#92c5de", "#0571b0"]); | |
d3.json("bcn.json", function(error, d) { | |
topojson.presimplify(d); | |
var map = new StaticCanvasMap({ | |
element: "body", | |
data: [ | |
{ | |
features: topojson.feature(d, d.objects["bcn"]), | |
static: { | |
paintfeature: function(parameters, d) { | |
parameters.context.fillStyle = color(d.properties.rate); | |
parameters.context.fill(); | |
parameters.context.lineWidth = 0.5; | |
parameters.context.strokeStyle = "rgba(0,0,0,0.2)"; | |
parameters.context.stroke(); | |
} | |
} | |
} | |
] | |
}); | |
map.init(); | |
}); | |
</script> |