Zooming bar-graph with d3.js

后端 未结 2 1881
盖世英雄少女心
盖世英雄少女心 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.

    0 讨论(0)
  • 2020-12-16 21:00

    I'm wondering the same thing, so at least know you're in good company. Here's my current approach. First of all, I can't generate a plot from your code and the links don't send me to anything useful -- no chart renders. So I can't help with your specific problem. However, there is an example that has zoomable rectangles here: http://bl.ocks.org/1962173. I'm currently going through it and deleting unnecessary elements and seeing if I can make it work. Hopefully this helps!

    0 讨论(0)
提交回复
热议问题