将轴文本标签放在刻度线之间

时间:2015-03-18 15:45:50

标签: d3.js label

如何根据标记更改标签的放置位置?

目前我有: enter image description here

但我显然不希望日期被勾号打断。我想要这个: enter image description here

我试过了:

.selectAll(".tick text")
.style("text-anchor", "start")

.selectAll("text")
  .attr("x", 5)
  .attr("dy", null)
  .attr("text-anchor", null);

svg.selectAll(".axis2 text")
.attr("dx", -115);

以上都没有移动文本标签。

任何建议都表示赞赏!

1 个答案:

答案 0 :(得分:1)

要选择text元素,请使用axisContainer.selectAll("text"),其中axisContainer是您调用xAxis2的选择变量的名称。然后你可以在它们上设置属性/样式。

相关问题