我是javascript和d3的新手,我一直在使用一些共享代码,并且一直在尝试修改它。D3根据数据改变链接的颜色
这是我目前有:
https://gist.github.com/erich-kuehn/2770a7c7c1cd633f6b47ebb21b640f68
其基于关闭的:
http://bl.ocks.org/erikhazzard/6201948
我试图改变链接的基础上一个新的领域颜色我添加了称为status的csv。它似乎运行良好,如果我通过代码,它似乎使一些链接红色和一些绿色,但当它完成后,他们都结束了绿色。思考?对不起,我真的很新。
//update
for(var i=0, len=links.length; i<len; i++){
if (links[i].status[0][0] === 'red') {
pathArcs.attr({
//d is the points attribute for this path, we'll draw
// an arc between the points using the arc function
d: path
})
.style({
stroke: 'red',
'stroke-width': '2px'
})
// Uncomment this line to remove the transition
.call(lineTransition);
//exit
pathArcs.exit().remove();
}else{
pathArcs.attr({
//d is the points attribute for this path, we'll draw
// an arc between the points using the arc function
d: path
})
.style({
stroke: 'green',
'stroke-width': '2px'
})
// Uncomment this line to remove the transition
.call(lineTransition);
//exit
pathArcs.exit().remove();
}
}
});