admin管理员组文章数量:1417471
I am creating some paths ina tree-graph in D3 and I'd like to change the color of the lines (paths), but I can't make my code work:
// Enter any new links at the parent's previous position.
link.enter().insert("svg:path", "g")
.attr("class", "link")
.attr("d", function(d) {
var o = {x: source.x0, y: source.y0};
return diagonal({source: o, target: o});
})
.transition()
.duration(duration)
.attr("d", diagonal);
// Transition links to their new position.
link.transition()
.duration(duration)
.attr("d", diagonal);
// Transition exiting nodes to the parent's new position.
link.exit().transition()
.duration(duration)
.attr("d", function(d) {
var o = {x: source.x, y: source.y};
return diagonal({source: o, target: o});
})
.remove();
I tried using the following to change and I've look-up up a few other solution, but I can't really understand what I need to select in my update selection to change it.
link.selectAll("path")
.attr("stroke", "#000000");
Thanks for the help in advance.
I am creating some paths ina tree-graph in D3 and I'd like to change the color of the lines (paths), but I can't make my code work:
// Enter any new links at the parent's previous position.
link.enter().insert("svg:path", "g")
.attr("class", "link")
.attr("d", function(d) {
var o = {x: source.x0, y: source.y0};
return diagonal({source: o, target: o});
})
.transition()
.duration(duration)
.attr("d", diagonal);
// Transition links to their new position.
link.transition()
.duration(duration)
.attr("d", diagonal);
// Transition exiting nodes to the parent's new position.
link.exit().transition()
.duration(duration)
.attr("d", function(d) {
var o = {x: source.x, y: source.y};
return diagonal({source: o, target: o});
})
.remove();
I tried using the following to change and I've look-up up a few other solution, but I can't really understand what I need to select in my update selection to change it.
link.selectAll("path")
.attr("stroke", "#000000");
Thanks for the help in advance.
Share Improve this question edited May 13, 2014 at 13:40 laaposto 12.2k15 gold badges58 silver badges72 bronze badges asked May 13, 2014 at 13:38 Sina SohiSina Sohi 2,7799 gold badges36 silver badges51 bronze badges 3-
1
link.style("stroke", "black")
– Lars Kotthoff Commented May 13, 2014 at 13:50 - Thank you. Why don't I have to select path in this case? – Sina Sohi Commented May 13, 2014 at 14:01
-
The
link
selection contains the path elements. – Lars Kotthoff Commented May 13, 2014 at 14:02
2 Answers
Reset to default 4I'm just starting with d3 myself, but I think you need to use link.style("stroke",#xxxxxx).
An svg can change the color by using fill attribute (same is plex for path attribute even though its children of svg)
svg
.data([newValue])
.transition()
.duration(1500)
.attr('fill', function(d) { return color(d); })
Working code for your reference:
https://jsfiddle/pjrc0yy3/1/
本文标签: javascriptHow do I change the color of path in D3jsStack Overflow
版权声明:本文标题:javascript - How do I change the color of path in D3.js? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745262995a2650440.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论