在 my NVD3 chart here ,我旋转并平移了 X 轴刻度
。因此,X 轴标签 My X-axis
也受到了影响。
JS:
var xTicks = d3.select('.nv-x.nv-axis > g').selectAll('g');
xTicks
.selectAll('text')
.attr('transform', function(d,i,j) {
return 'translate (-10, 40) rotate(-90 0,0)';
)}
如何修改此代码以跳过 X 轴标签的格式设置?
最佳答案
您之前已选择了要转换的所有 text
元素。仅选择勾号
标签。
尝试以下方法
xTicks.selectAll('g > .tick > text').attr('transform', function(d, i, j) {
return 'translate (-10, 40) rotate(-90 0,0)'
});
// Bring the 'My X-Axis' label down to avoid overlap.
xTicks.select('.nv-axislabel').attr("y", 90)
希望对你有帮助
关于javascript - X 轴标签错位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24525794/