简体   繁体   English

如何设置d3.brush范围对吗?

[英]how to set d3.brush extent right?

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. 我正在编写一个基于Mike Bostocks示例的d3小部件http://bl.ocks.org/mbostock/1667367所以我试图用预定义的日期设置画笔范围,但是范围矩形不适用于那些日期。

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 这里的整个代码http://plnkr.co/edit/H3nt9t8pw0nXM4yHp25P?p=preview

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 工作代码在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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