NVD3.js multiChart x-axis labels is aligned to multiple lines, but not multiple bars

前端 未结 6 923
暗喜
暗喜 2021-01-05 16:50

This question relates to NVD3.js multiChart x-axis labels is aligned to lines, but not bars

I am using NVD3.js multiChart to show multiple lines

6条回答
  •  广开言路
    2021-01-05 17:45

    I encountered the same problem and fixed it with below code:

    at lines 7832 and 7878 replace

    .attr('transform', function(d,i) { return 'translate(' + x(getX(d,i)) + ',0)'; })
    

    with :

    var w = (x.rangeBand() / (stacked && !data[j].nonStackable ? 1 : data.length));
    var sectionWidth = availableWidth/(bars.enter()[0].length - 1);
    if(bars.enter().length == 2)
        return 'translate(' + ((i-1)*w + i*w + (i*(sectionWidth - 2*w))) + ',0)';
    else
        return 'translate(' + ((i-0.5)*w + i*(sectionWidth - w)) + ',0)';
    

    The first case handles multiple bars case while the second one handles single bar case.

提交回复
热议问题