【发布时间】:2016-06-20 17:32:21
【问题描述】:
我试图移动我的桑基图上最右边的节点的标签以跟随节点而不是在节点之前。我正在使用here 显示的代码。
我可以通过键入如下所示的过滤功能行来让文本跟随节点
// add in the title for the nodes
node.append("text")
.attr("x", -6)
.attr("y", function(d) { return d.dy / 2; })
.attr("dy", ".35em")
.attr("text-anchor", "end")
.attr("transform", null)
.text(function(d) { return d.name + " ("+Math.round(d.value).toLocaleString('en') + ")"; })
//.filter(function(d) { return d.x < width / 2; })
.attr("x", 6 + sankey.nodeWidth())
.attr("text-anchor", "start");
但是,现在这个文本被右边距截断了。即使调整屏幕的宽度,它仍然会被切断。我怀疑代码中有一行最右边的节点位于右边距。我是 1) 试图找到这一行和 2) 试图使它应用于文本而不是节点。
【问题讨论】:
-
更改
var margin = {top: 10, right: 10, bottom: 10, left: 10}byvar margin = {top: 10, right: 10, bottom: 10, left: 30}能解决您的问题吗?
标签: javascript d3.js sankey-diagram