how to set d3.brush extent right?

廉价感情. 提交于 2019-12-31 02:20:28

问题


I am writing a d3 widget based on Mike Bostocks example http://bl.ocks.org/mbostock/1667367 So I am trying to set brush extent with predefined dates, but the extent rectangle is not applied to those dates.

var brush = d3.svg.brush()
            .x(x2)
            .extent([new Date("May 2001"), new Date("May 2002")])
            .on('brush', brushed);

...

the entire code here http://plnkr.co/edit/H3nt9t8pw0nXM4yHp25P?p=preview


回答1:


As I understood, you want to set initially the date period. You'll need to call brush component with desired extent.

        brush.extent([new Date("May 2001"), new Date("May 2002")]);
        context.select('.brush').call(brush);
        brushed();

Working code is here



来源:https://stackoverflow.com/questions/24350893/how-to-set-d3-brush-extent-right

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!