[英]D3 Stacked Bar Chart add Data Labels and solving D3 Label Placement
I have two questions. 我有两个问题。
I found this jsfiddle http://jsfiddle.net/3a5Wk/1/ code and I am very grateful if you can also put the answers in a jsfiddle or explain your code in more detail as I am just starting on d3-Charts. 我找到了这个jsfiddle http://jsfiddle.net/3a5Wk/1/代码,如果您也可以将答案放在jsfiddle中或在我刚开始使用d3-Charts时更详细地解释您的代码,我将不胜感激。
I have solved the issue of the first question by adding the Label code. 我已经通过添加标签代码解决了第一个问题。 I have added:
我已经添加了:
var dataText = svg.selectAll(".dtext")
.data(layers)
.enter().append("g")
.attr("class", "g")
dataText.selectAll("rect")
.data(function(d) { return d; })
.enter().append("text")
.attr("x", function(d) { return x(d.x) +18; })
.attr("y", function(d) { return y(d.y + d.y0) +10; })
.style("text-anchor", "middle")
.style("font-size", "10px")
.style("color", "white")
.text(function (d) {return (d.y);});
Now I still got the Problem that the labels overlap. 现在我仍然遇到标签重叠的问题。
How can I change the position of the labels in a way that they don't overlap? 如何以不重叠的方式更改标签的位置?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.