最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I get the index number from the array in d3? - Stack Overflow

programmeradmin1浏览0评论

In the following code how do I get the number for the index/row that is 'd'?

    var docs = svg.selectAll("g")
        .data(dataset)
      .enter()
        .append("g")
        .attr("id", function(d) { return d["Identifier"]})
        .attr("num", function(d) { return d}) // this
        .attr("x", function(d) { return xScale(d3.time.format.iso.parse(d["UserDate"]))})
        .attr("y", function(d) { return xScale(d3.time.format.iso.parse(d["UserDate"]))});

In the following code how do I get the number for the index/row that is 'd'?

    var docs = svg.selectAll("g")
        .data(dataset)
      .enter()
        .append("g")
        .attr("id", function(d) { return d["Identifier"]})
        .attr("num", function(d) { return d}) // this
        .attr("x", function(d) { return xScale(d3.time.format.iso.parse(d["UserDate"]))})
        .attr("y", function(d) { return xScale(d3.time.format.iso.parse(d["UserDate"]))});
Share Improve this question asked Jun 9, 2014 at 11:02 StephenStephen 1,0572 gold badges26 silver badges42 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

simply use :

function(d,i){ ... }

e.g.

.attr('id', function(d,i){return 'item'+i;})
发布评论

评论列表(0)

  1. 暂无评论