Zooming bar-graph with d3.js

后端 未结 2 1889
盖世英雄少女心
盖世英雄少女心 2020-12-16 20:17

I am trying to create a bar graph with a time scale where its possible to zoom into any time period. I was able to create the zooming functionality for my x-axis(time scale)

2条回答
  •  情话喂你
    2020-12-16 20:56

    Using 'selectAll', I've applied the scaling and translation to each bar respectively, restricting both scale and translation to the x-axis only.

    function zoom() {
        chart.select(".xaxis").call(xAxis);
        chart.select(".yaxis").call(yAxis);
        chart.selectAll(".chart rect").attr("transform", "translate(" + d3.event.translate[0] + ",0)scale(" + d3.event.scale + ", 1)");
    }
    

    This works equally well with a single path element, which is what I was trying to figure out when I stumbled upon your question.

提交回复
热议问题