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

Add y-axis gridlines to D3 Gantt chart

将水平网格线添加到 d3 甘特图(如 this example? I was originally thinking of making an axis and making the tick marks the length of the chart (as in this example)的最佳方法是什么,但这会将它们直接放在图表矩形的中间。

是否可以让轴在矩形周围刻度为 "lanes",或者只是更容易绘制线条(如 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);