从 topoJSON (D3) 选择国家 ID
Selecting country ID from topoJSON (D3)
我正在关注这个 tutorial "A simple d3.js map explained"。我想创建一张地图并更改单个国家/地区的颜色。
我简化了教程,只显示地图 Plunk
我想我可以通过在 topoJSON 中找到的 id select 一个国家
{"type": "Polygon",
"id": 604,
"arcs": [
[133, -473, -448, -378, -374, -413]
]
},
我知道英国是 "id": 826。我应该使用 ID 来更改单个国家/地区的颜色吗?我该怎么做?
你可以用.filter
到select你感兴趣的国家,然后按照你想要的方式处理。
示例:
// select a country by Id and change its styling
g.selectAll('path')
.filter(function(d) {
return d.id === 826
})
.style('fill', 'red')
演示:Updated plunk.
我正在关注这个 tutorial "A simple d3.js map explained"。我想创建一张地图并更改单个国家/地区的颜色。
我简化了教程,只显示地图 Plunk
我想我可以通过在 topoJSON 中找到的 id select 一个国家
{"type": "Polygon",
"id": 604,
"arcs": [
[133, -473, -448, -378, -374, -413]
]
},
我知道英国是 "id": 826。我应该使用 ID 来更改单个国家/地区的颜色吗?我该怎么做?
你可以用.filter
到select你感兴趣的国家,然后按照你想要的方式处理。
示例:
// select a country by Id and change its styling
g.selectAll('path')
.filter(function(d) {
return d.id === 826
})
.style('fill', 'red')
演示:Updated plunk.