gpt4 book ai didi

javascript - 如何更新 nvd3 图表中 xAxis 的边距或填充?

转载 作者:太空宇宙 更新时间:2023-11-04 11:19:45 27 4
gpt4 key购买 nike

公众号:http://plnkr.co/edit/ymrqIOGTBqF6TVMTvC4T?p=preview

^ 在我上面的例子中,xAxis 时间数据太靠近图表的底部,我一直在玩 CSS,但没有任何运气让任何东西移动。是否有另一种方法可以在 xAxis 时间数据和图表之间提供至少 5 像素的空间填充/边距?

enter image description here

我尝试过的:

#chart {
height: 400px;
}

.nv-axisMaxMin,
.nv-axisMaxMin-x,
.nv-axisMin-x {
position: relative;
top: 5px;
margin-top: 5px;
}

即使这样也行不通:

svg text {
font: 400 12px Arial;
margin-top: 5px;
position: absolute; // Just move! :'(
top: 10px;
}

最佳答案

更改 css 将不起作用,因为文本的 xy 值属性是动态生成的。

这是一个厚颜无耻的做法,

// FOR THE REGULAR VALUES
d3.selectAll('.nv-x.nv-axis > .nv-wrap.nv-axis > g > g.tick > text').each(function(d,i){
d3.select(this).attr('dy', '2em');
});

// For the MIN and MAX values
d3.selectAll('.nv-x.nv-axis > .nv-wrap.nv-axis > .nv-axisMaxMin > text').each(function(d,i){
d3.select(this).attr('dy', '2em');
})

希望对您有所帮助。

关于javascript - 如何更新 nvd3 图表中 xAxis 的边距或填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32892478/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com