将csv数据绑定到topojson路径 - cloropleth [英] Bounding csv data to topojson path - cloropleth

查看:286
本文介绍了将csv数据绑定到topojson路径 - cloropleth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图绑定一些数据到topojson地图。
到目前为止,我已经能够绘制美国的地图,每个路径标记为id:state name。
现在我想做的是将我对外部csv的数据绑定到地图,以显示基于csv(aka cloropleth)中的值的色调的每个状态。
我一直在寻找指南,但我还没有知道还没有理解在Mike Bostock的网站上,所以我试图绑定的颜色与一个像这样的函数:

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; })) + ")")

工作。
该页面位于: http://www.dropbox.com/s/ w2pe4omn895vt83 / usa_malattie.html

注释掉最后一个零件,使用csv载入,为地图提供工具提示,当载入csv时也会消失数据。
任何有关如何解决这个问题的帮助将非常感谢,提前感谢!

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!

编辑:csv看起来像这样:

the csv looks like this:

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

topojson就像这样:

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"}},


b $ b

链接: http://dl.dropboxusercontent。 com / u / 37967455 / usa_malattie / death_parse.csv
topojson的链接: http://dl.dropboxusercontent.com/u/37967455/usa_malattie/usatopo.json

推荐答案

您可以尝试以下命令:

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

这篇关于将csv数据绑定到topojson路径 - cloropleth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆