gpt4 book ai didi

javascript - 将 y 轴网格线添加到 D3 甘特图

转载 作者:行者123 更新时间:2023-11-29 18:57:31 32 4
gpt4 key购买 nike

this example 中的 d3 甘特图添加水平网格线的最佳方式是什么? ?我最初想制作一个轴并使刻度标记为图表的长度(如 this example 中所示),但这会将它们直接放在图表矩形的中间。

是否有可能使轴刻度到矩形周围的“ channel ”中,或者只是更容易绘制线条(如 here 所做的那样)?

最佳答案

解决方案来自this issue post on GitHub .基本上只需将轴组平移带宽度的一半:

var yScale = d3.scaleBand()
.domain(lanes)
.rangeRound([0, chartHeight], 0.1);

var yGridAxis = d3.axisLeft()
.scale(yScale)
.tickFormat('')
.tickSize(-chartWidth);

chart.append('g')
.attr('class', 'grid')
.attr('transform', function(d) {
return 'translate(0,' + (-yScale.bandwidth()/2) + ')';
})
.call(yGridAxis);

关于javascript - 将 y 轴网格线添加到 D3 甘特图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48711277/

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