javascript - 向 d3 底轴添加高度或填充
问题描述
我试图用 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 度时,它会从图表中消失,并且因为我有溢出:隐藏在 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);
推荐阅读
- r - 将数据转换为矩阵后如何按列制作词频表和词云?尺寸小,贴工作R代码
- sql - 没有连接的 SQL 查询
- java - 无法从 Firebase 实时数据库 Android 检索数据
- swift - 设置 SwiftUI 变量
- node.js - 一种从 NodeJS 中的音频文件获取音量级别的方法
- javascript - 为什么 React 在没有被点击的情况下调用 onClick 函数?
- bash - 通过 ssh 运行 bash 显示错误:/usr/bin/env: bash: No such file or directory
- wordpress - 在 Wordpress 中如何加载 functions.php?
- php - PHP路由不包括文件
- php - 我想使用 Laravel 连接根据条件返回特定数量的记录