0
我很努力在D3版本4圖表中爲垂直標籤添加垂直標籤。我認爲問題在於,根據SVG標準,<text>
元素不能在<rect>
元素內,但在我的生活中,我無法弄清楚如何讓<text>
元素出現在<rect>
元素的外部。有問題的代碼是在這裏:標籤不會在D3 v4條形圖中顯示
g.selectAll(".bar")
.data(data)
.enter().append("rect")
.attr("class", "bar")
.attr("y", function(d) { return y(d.Country); })
.attr("x", function(d) { return x(d.freqStart); })
.attr("width", function(d) { return x(d.freqEnd) - x(d.freqStart); })
.attr("height", y.bandwidth())
.append("text")
.attr("class", "label")
.attr("transform", "rotate(-90)")
.text(function(d) { return d.Operator; });
完整的代碼可以在
https://plnkr.co/edit/JiuYKhRxgqtG1osYjJHq?p=preview
就像一個魅力。非常感謝!特別感謝解決方案的明確解釋! – SteveSong