當域值不同時,代碼可以正常工作。但當所有域值均為 0 時,條形高度變?yōu)?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 時,D3 范圍返回 graphHeight 的一半而不是 0
ITMISS
2023-09-21 10:52:45