【发布时间】:2017-02-02 23:22:05
【问题描述】:
我正在尝试重现 M. Bostock 著名的 Choropleth example,但使用的是按州而不是按县着色。我大部分时间都在工作,但是由于某种原因,前几个状态没有渲染。通过研究其他问题,我认为这可能是selectAll issue 或 d3 如何解析索引的问题,但我似乎无法理解它。
下面是我进入并渲染状态的具体函数:
function testMap(error, us){
if(error) throw error;
svg.append("g")
.attr("class", "states")
.selectAll("path")
.data(topojson.feature(us, us.objects.states).features)
.enter().append("path")
.attr("fill", function(d) { return color(d.value = num.get(d.id)); })
.attr("d", path)
.append("title")
.text(function(d) { return state.get(d.id) + ", " + d.value; });
svg.append("path")
.datum(topojson.mesh(us, us.objects.states, function(a, b) { return a !== b; }))
.attr("class", "states")
.attr("d", path);
Here's a working JSFiddle with my issue
PS:我应该注意,我试图在这个例子中使用 d3 v4,我了解到它与 v3 有很大的不同。
【问题讨论】:
标签: d3.js