简体   繁体   English

将D3 Band Zoom从v3升级到v4

[英]Upgrading D3 Band Zoom from v3 to v4

I'm trying to update this fiddle to D3 v4 我正试图将这个小提琴更新为D3 v4

http://jsfiddle.net/AdamMills/Ljeh2etj/ http://jsfiddle.net/AdamMills/Ljeh2etj/

This is the original zoom function 这是原始缩放功能

bars.attr("transform", "translate(" + d3.event.translate[0]+",0)scale(" + d3.event.scale + ",1)");
chart.select(".x.axis").attr("transform", "translate(" + d3.event.translate[0]+","+(height)+")")
    .call(xAxis.scale(x.rangeRoundBands([0, width * d3.event.scale],.1 * d3.event.scale)));
chart.select(".y.axis").call(yAxis);

I have tried to update it per the docs for d3-zoom 我试图根据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);

I'm getting an undefined error in recaleX What am I missing? 我在recaleX中遇到一个未定义的错误我错过了什么?

You could change second row in zoom function from fiddle: 您可以从小提琴中更改缩放功能的第二行:

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)));;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM