我正在尝试将
this fiddle更新为D3 v4
http://jsfiddle.net/AdamMills/Ljeh2etj/
这是原始缩放功能
bars.attr("transform","translate(" + d3.event.translate[0]+",0)scale(" + d3.event.scale + ",1)"); chart.select(".x.axis").attr("transform","+(height)+")") .call(xAxis.scale(x.rangeRoundBands([0,width * d3.event.scale],.1 * d3.event.scale))); chart.select(".y.axis").call(yAxis);
我试图根据d3-zoom的文档更新它
bars.attr("transform",d3.event.transform); chart.select(".x.axis").attr("transform",d3.event.transform) .call(xAxis.scale(d3.event.transform.rescaleX(x))); chart.select(".y.axis").call(yAxis);
解决方法
您可以从小提琴中更改缩放功能的第二行:
chart.select(".x.axis") .attr("transform","translate(" + d3.event.transform.x + "," + (height) + ")") .call( xAxis.scale( x.rangeRound([0,width * d3.event.transform.k]) .paddingInner(.1 * d3.event.transform.k)));;