javascript - 在 d3 图表中,我的 xAxis 刻度文本未完全显示
问题描述
我在我的项目中使用 d3 图表,在我的图表中,我正在formatToDateAndTime
格式化我的xAxis
刻度以显示特定格式的日期。
我看到的问题是我的 xAxis 刻度文本没有完全出现,它从开始就被切断了。
下图显示的第一个值应该oct 16 12:00 AM
像这样'',但它只显示' 16 12:00 AM
'在刻度。
这是我的代码 -
var xAxis = d3
.axisBottom(xScale)
.ticks(5);
const formatToDateAndTime = d3.timeFormat("%b %d %I:%M %p"); // e.g.Sep 18 02:30 PM
xAxis.tickFormat((d, index) => {
return formatToDateAndTime(d);
});
请指导我如何解决这个问题。
解决方案
我通过添加使用 transform 属性解决了这个问题.attr("transform", "translate(40, " + height + ")")
我的代码 -
g.append("g")
.attr("class", "x axis")
.attr("id", "axisX")
.attr("transform", "translate(40, " + height + ")")
.call(xAxis);
我不确定这是否是最好的解决方案,但这就是我解决这个问题的方法。
推荐阅读
- javascript - 画布线性渐变采用另一个输入类型颜色字段的值
- php - 在另一个 foreach 中提高 foreach 的性能
- php - php中某些标点符号之前的粗体部分
- java - 通过 Java 中的 MP3 源流式传输音频
- html - 从带有事件代码的 HTML 下拉列表(SELECT 标记和 OPTIONS 标记)中选择的 VBA 代码
- java - 初始化应用程序上下文后,如何在 Spring Boot 中连接到多个数据源?
- dataframe - 如何验证 Pyspark 中列的日期格式?
- java - Android 文件系统 - 即使我有权限也无法写入文件
- python - 在python中合并两个熊猫数据框
- ios - iOS 14.0.1 崩溃问题