简体   繁体   中英

Setting an id issue in d3

So this is what I'm doing:

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.

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.

What am I doing wrong?

我想通了,显然ids不能以数字开头。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM