我有通过D3生成的折线图,文本显示在悬停时指针的右侧。问题是出现在最右边的文本是由SVG的边缘切断的。我知道一个简单的overflow:visible
会允许它出现在外面,但我希望它留在SVG中。这可能吗?
答案 0 :(得分:7)
您可以使用此技术:
使用(svg_width / 2)
获取中间
text.style ("text-anchor", function () {
var position = d3.mouse(); // position[0] <= x position[1] <= y
if (position[0] < (svg_width/2) ) {
// you are on A zone
return "start";
} else {
// you are on B zone
return "end";
}
})