将csv数据绑定到topojson路径

编程入门 行业动态 更新时间:2024-10-11 07:27:57
本文介绍了将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; })) + ")")

工作。 该页面位于: www.dropbox/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的链接: dl.dropboxusercontent/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路径

本文发布于:2023-08-03 12:39:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1287096.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   路径   数据   csv   topojson

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!