我正在从https://bl.ocks.org/d3noob/5028304中的示例制作d3 Sankey图。此示例适用于较小的数据集。当我切换为使用更大的数据集时,可视化就会中断。看起来问题在于dy值变为负数。
在控制台中,错误是:
Error: <rect> attribute height: A negative value is not valid. ("-9.02557856272838")
Run Code Online (Sandbox Code Playgroud)
它指向的代码是:
node.append("rect")
.attr("height", function(d) { return d.dy; })
Run Code Online (Sandbox Code Playgroud)
这可能是因为情节不在屏幕上了吗?我看过使用d3音阶,但不确定如何实现它们。也许是这样的:
d3.scale.ordinal()
.domain(data.map(function(d) { return d.name; }))
.rangeRoundBands([0, height], .2);
Run Code Online (Sandbox Code Playgroud)
或者,也许有一种方法可以随着数据集变大而缩小可视化范围,从而使所有内容都适合容器。
这是我的代码:https : //plnkr.co/edit/hOjEBHhS7vfajD2wb8t9?p=preview