在d3中设置ID问题 [英] Setting an id issue in d3
本文介绍了在d3中设置ID问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以这是我在做什么:
selection = canvas.selectAll("circle").data(mydata)
selection.enter().append("circle")
selection
.attr("id", function(d, i){ var result = i+''; return result; })
总之,的每个元素作为其索引的字符串表示。
In short, I'm trying to set the id of each element to be a string representation of its index.
然而,当我以后尝试使用 d3.select(#1)
或者使用数字变量i并且 d3.select(#+ i.toString())
,似乎没有什么工作。
However, when I try to access that particular element later by using d3.select("#1")
or by using a number variable i and going d3.select("#" + i.toString())
, nothing seems to work.
我做错了什么?
推荐答案
,显然ids不能以数字开头。
I figured it out, apparently ids can't start with a number.
这篇关于在d3中设置ID问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文