Javascript 当所有域输入值均为0时,D3范围返回图形高度的一半而不是0
当域值不同时,代码工作正常 但当所有域值都为0时,条形图高度变为140,这是图形高度的一半,而不是0 以下是我的代码示例:Javascript 当所有域输入值均为0时,D3范围返回图形高度的一半而不是0,javascript,d3.js,Javascript,D3.js,当域值不同时,代码工作正常 但当所有域值都为0时,条形图高度变为140,这是图形高度的一半,而不是0 以下是我的代码示例: const x = d3.scaleBand() .rangeRound([0, graphWidth]) .padding(0.4); const y = d3.scaleLinear() .rangeRound([graphHeight, 0]); const draw = (data) =
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))
}
此问题发生在d3 v5中。所以,我用D3V4解决了这个问题