Built with blockbuilder.org
Created
January 31, 2020 16:30
-
-
Save ddonatien/7a4c8875f95d51b4ea204c9a64465dc4 to your computer and use it in GitHub Desktop.
TD Grippe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| license: mit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <script src="https://d3js.org/d3.v4.min.js"></script> | |
| <script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script> | |
| <script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script> | |
| <style> | |
| body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
| </style> | |
| </head> | |
| <body> | |
| <script> | |
| var width = 700, | |
| height = 580; | |
| var dataCsv = "https://lyondataviz.github.io/teaching/lyon1-m2/2017/data/GrippeFrance2014.csv"; | |
| 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 path = d3.geoPath() // d3.geo.path avec d3 version 3 | |
| .projection(projection); | |
| d3.csv(dataCsv, function(data) { | |
| let color = d3.scaleOrdinal(d3.schemeGreens[7]) | |
| .domain([0, 2000]); | |
| maxValue = 0 | |
| d3.json("regions.json", function(json) { | |
| //On fusionne les donnees avec le GeoJSON des regions | |
| let geoGrippe = {}; | |
| for (var i = 0; i < data.length; i++) { | |
| let dataValue= parseFloat(data[i].somme2014); | |
| if (dataValue > maxValue) maxValue = dataValue; | |
| geoGrippe[data[i].region] = dataValue; | |
| } | |
| color.domain([0, maxValue]); | |
| svg.selectAll("path") | |
| .data(json.features) | |
| .enter() | |
| .append("path") | |
| .attr("d", path) | |
| .style("fill", function(d) { | |
| var value = geoGrippe[d.properties.nom]; | |
| return color(value) | |
| }); | |
| }); | |
| }); | |
| </script> | |
| </body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment