Built with blockbuilder.org
forked from aurelient's block:
forked from aurelient's block: TP4 Data viz UCBL 2017
forked from Renaud-D-Harreville's block: TP4 Data viz UCBL 2017
forked from anonymous's block: TP4 Data viz UCBL 2017
forked from anonymous's block: TP4 Data viz UCBL 2017
xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
var grippeDataLink = "https://lyondataviz.github.io/teaching/lyon1-m2/2017/data/GrippeFrance2014.csv";
var width = 700,
height = 580;
var svg = d3.select( "body" )
.append( "svg" )
.attr( "width", width )
.attr( "height", height );
var projection = d3.geoConicConformal().center([2.454071, 46.279229]).scale(2800);
//var projection = d3.geoAlbersUsa() // d3.geo.albersUsa avec d3 version 3
// .translate([width/2, height/2])
var path = d3.geoPath() // d3.geo.path avec d3 version 3
.projection(projection);
//c = d3.scaleOrdinal(d3.schemeCategory10);
// On definit une echelle de couleur
var color = d3.scaleQuantize()
.range(["rgb(237,248,233)", "rgb(186,228,179)",
"rgb(116,196,118)", "rgb(49,163,84)", "rgb(0,109,44)"]);
color.domain([0, 2000]);
d3.csv("grippe.csv", function(data) {
console.log(data);
var sum = 0;
for (var i = 0; i < data.length; i++) {
sum += data[i]["somme2014"];
}
d3.json("france.json", function(json) {
//On fusionne les donnees avec le GeoJSON des regions
for (var i = 0; i < data.length; i++) {
var total = data[i]["somme2014"];
//console.log(data);
var ratio = (total / sum) * 2000 * 100
//(+data[i]["01/06/14"] * 2000 * 100) / total;
//console.log(ratio);
json.features[i].properties["value"] = ratio;
}
svg.selectAll("path").data(json.features).enter()
.append("path")
.style("fill", function(d) { return color(d.properties.value); })
.attr("d", path);
});
});
</script>
</body>
https://d3js.org/d3.v4.min.js