Bounding csv data to topojson path - cloropleth

喜夏-厌秋 提交于 2019-12-08 07:16:35

问题


I am trying to bound some data to a topojson map. So far I've been able to draw the map of the US, with each path labeled by id: state name. What I'd like to do now is to bind data I have on an external csv to the map, to show each state of a hue based on the value in the csv (aka cloropleth). I've been looking for guides but I don't have the knowledge yet to understand the one on Mike Bostock's site, so I tried to bind the color with a function like so:

.attr("fill", "rgb(0, 0, " + Math.round(d.value * 255 / d3.max(d, function (d) {return d.value; })) + ")")

but it doesn't work. The page is here: http://www.dropbox.com/s/w2pe4omn895vt83/usa_malattie.html

Commenting out the last part, with the csv load, gives the map with the tooltip showing, that also disappear when loading the csv data. Any help on how to resolve this would be highly appreciated, thanks in advance!

EDIT: the csv looks like this:

id,value
"Kentucky",207.4
"Mississippi",200.5
"West Virginia",196.6
"Louisiana",196.4

the topojson like this:

{"type":"Topology","transform":{"scale":
0.011125945304891298,0.005248969801868182],
"translate":[-178.21759836236586,18.92178634508703]},
"objects":{"usa":{"type":"GeometryCollection",
"geometries":[{"type":"MultiPolygon","id":"Hawaii",
"arcs":[[[0]],[[1]],[[2]],[[3]],[[4]],[[5]],[[6]]],
"properties":{"STATE_NAME":"Hawaii"}},

link for the csv: http://dl.dropboxusercontent.com/u/37967455/usa_malattie/death_parse.csv link for the topojson: http://dl.dropboxusercontent.com/u/37967455/usa_malattie/usatopo.json


回答1:


You may try the following command:

topojson -o final.json -e death_parse.csv --id-property=id -p STATE_NAME,color=+value -- usatopo.json


来源:https://stackoverflow.com/questions/18466584/bounding-csv-data-to-topojson-path-cloropleth

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!