简体   繁体   中英

Upgrading D3 Band Zoom from v3 to v4

I'm trying to update this fiddle to D3 v4

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

    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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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