当域值不同时,代码可以正常工作。但当所有域值均为 0 时,条形高度变为 140,即 graphHeight 的一半,而不是 0。这是我的代码示例:const x = d3.scaleBand() .rangeRound([0, graphWidth]) .padding(0.4);const y = d3.scaleLinear() .rangeRound([graphHeight, 0]);const draw = (data) => {x.domain(data.map(function(d) {return d.type;}));y.domain([0, d3.max(data, function(d) {return d.number;})]);rects.enter() .append('rect') .on('mouseover', onMouseOver) .on('mouseout', onMouseOut) .merge(rects) .attr('fill', '#30aaed') .attr('x', d => x(d.type)) .attr('y', d => y(d.number)) .attr('width', x.bandwidth()) .attr('height', d => graphHeight - y(d.number))}
添加回答
举报
0/150
提交
取消