【发布时间】:2016-10-23 02:42:54
【问题描述】:
我正在使用 D3 Sankey 插件创建一个 Sankey 图。我有标准列:源、目标、值加上一个名为 nodeColor 的附加列。我希望目标节点的颜色由“nodeColorTarget”列中记录的颜色决定。我能够将节点的源代码更改为全一种颜色。但是,我无法开发一个函数来使用附加列来指示颜色。
样本数据:
source,target,value,nodeColorTarget
Dist A,Place1,1,red
DistB,Place1,5,red
DistB,Place2,2,grey
DistB,Place2,1,grey
DistB,Place3,2,blue
现有代码:
// add the rectangles for the nodes
node.append("rect")
.attr("height", function(d) { return d.dy; })
.attr("width", sankey.nodeWidth())
.style("fill", "red")
//.style("fill", function(d) {
//return d.color = color(d.name.replace(/ .*/, "")); })
//.style("stroke", function(d) {
// return d3.rgb(d.color).darker(2); })
//.append("title")
// .text(function(d) {
// return d.name + "\n" + format(d.value); });
我的完整代码是here。
【问题讨论】:
-
我更新了答案
标签: javascript d3.js colors sankey-diagram