首页 > 解决方案 > 取消缩放后图表外部的 D3 条形图

问题描述

我有一个使用 D3 的堆积条形图。x 轴是日期。还有对焦变焦。我根据可缩放堆叠条形图测试开始图表 我在取消缩放时遇到的问题。我无法让酒吧回到可视区域。我认为问题出在刷过的功能上。但是想不通。

function brushed() {
    // update the main chart's x axis data range
    x.domain(brush.empty() ? xOverview.domain() : brush.extent());
    // redraw the bars on the main chart
    layer.selectAll(".bar")
        .attr("transform", function (d) { return "translate(" + x(d.x) + ",0)"; })
    // redraw the x axis of the main chart
    layer.select(".x.axis").call(xAxis);
}

我有一个关于 js fiddle 的完整示例:js fiddle example

缩放后如何使条形图回到可视区域?谢谢!

标签: javascriptd3.js

解决方案


推荐阅读