gpt4 book ai didi

javascript - 向 d3 底轴添加高度或填充

转载 作者:太空宇宙 更新时间:2023-11-04 06:44:49 25 4
gpt4 key购买 nike

我尝试使用 d3 和 Vue.js 制作图表,但我的 X 轴出现问题,我似乎无法为其添加填充或高度。

这是我的示例代码:

this.graph.g
.select('.axes-wrapper')
.append('g')
.attr('class', 'axis axis-x')
.style('font-size', '15px')
.attr('transform',`translate(0,${this.graph.height})`)
.attr('x', this.graph.width / 2)
.call(d3.axisBottom(this.graph.x).ticks(10).tickFormat(d3.timeFormat('%d %b %y')))
.selectAll('text')
.attr('transform', 'rotate(-45)')
.attr('x', -20)
.attr('y', 10);

我遇到的问题是,当我将字体大小设置为 15px 并将我的文本旋转 45 度时,它超出了图表,并且因为我有 overflow:hidden 在 svg 元素上它不可见。但是我不能将溢出设置为可见,因为它会导致其他一些问题,所以有什么方法可以设置高度或向我的 X 轴添加底部填充??

最佳答案

在此处调整边距:-

 var  margin = { top: 10, right: 30, bottom: 50, left: 20 };
var svg = d3.select('#some-id').append('svg')
.attr('width', 500 + margin.right + margin.left)
.attr('height', 500 + margin.top + margin.bottom);

关于javascript - 向 d3 底轴添加高度或填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53403566/

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