我试图在此图表中添加点http://bl.ocks.org/nsonnad/4175202
countryEnter.selectAll("dot")
.data(data)
.enter().append("circle")
.attr("r", 3.5)
.attr("cx", function(d) { return x(d.year); })
.attr("cy", function(d) { return y(d.name); });
但这不起作用https://plnkr.co/edit/ADuZkJQrq7mjZqDZwrBe
可能有人可以帮忙吗?
最佳答案
使用嵌套选择时,您的data调用可以返回部分数据。在这种情况下,values
数组:
countryEnter.selectAll("dot")
.data(function(d){
return d.values; //<-- return just the values of your larger data-binding
})
.enter().append("circle")
.attr("r", 3.5)
.attr("cx", function(d) { return x(d.year); })
.attr("cy", function(d) { return y(d.stat); });
更新了code。
关于javascript - 在D3图表中添加点,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36548760/