我有这个代码:
path = group.append("svg:path")
.attr("d", arc)
.style("fill", function(d) {
if (d.children)
return color(d.name)
else
return "grey"
})
.attr("display", function(d) {
return d.depth ? null : "none";
})
.each(stash);
但我不仅想向样式添加“填充”,还想添加笔划,具体来说就是这段代码:
.style("fill", function(d) {
if (d.children)
return color(d.name)
else
return "grey"
})
谁能告诉我如何添加描边吗?我无法在 CSS 中执行此操作,因为它需要特定于该特定路径并且没有 id 或类。
最佳答案
您可以将多个 style
或 attr
调用链接在一起(就像您在代码中使用 fill
和 display
示例)那么这是否达到了您想要的效果?
path = group.append("svg:path")
.attr("d", arc)
.style("fill", function(d) {
if (d.children)
return color(d.name);
else
return "grey";
})
.attr("stroke", function(d) {
if (d.children)
return "red";
})
.attr("stroke-width", function(d) {
if (d.children)
return 2;
else
return 0;
})
.attr("display", function(d) {
return d.depth ? null : "none";
})
.each(stash);
不过,根据 d.children
的结果应用一个类似乎会更清晰。
关于javascript - D3 Graph - 将描边添加到路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49856286/