d3数据索引为零

时间:2013-08-04 17:34:46

标签: svg d3.js

以下代码在运行时向控制台输出10个零(0)。我期待0,1,2,3 ......

var data = [{"id":1,"adjX":-1,"adjY":-1,"weight":1},
{"id":2,"adjX":-2,"adjY":0,"weight":1},
{"id":3,"adjX":0,"adjY":2,"weight":2},
{"id":4,"adjX":3,"adjY":-1,"weight":3},
{"id":5,"adjX":-2,"adjY":-6,"weight":5},
{"id":6,"adjX":-10,"adjY":-2,"weight":8},
{"id":7,"adjX":3,"adjY":15,"weight":13},
{"id":8,"adjX":24,"adjY":-6,"weight":21},
{"id":9,"adjX":-10,"adjY":-40,"weight":34},
{"id":10,"adjX":-63,"adjY":15,"weight":55}]

.
.

svg.selectAll("line")
    .data(data)
    .enter().append("line")
    .attr("x1", function(d,i){
        console.log(i);
            return varX+(i*5);
         })
    .attr("y1", function(d,i){return varY+(i*5);})
    .attr("x2", function(d,i){return varX+(i*10);})
    .attr("y2", function(d,i){return varY+(i*10);});

为什么呢?请帮助:)

0 个答案:

没有答案