简体   繁体   English

根据笔刷范围更新圆环图弧

[英]Update a Donut Chart Arc Based on a Brush Extent

在此处输入图片说明

I'm using a D3 brush to update the arcs of a donut chart , but the update is occurring only after I release the brush. 我正在使用D3画笔更新甜甜圈图的圆弧 ,但是仅在释放画笔后才进行更新。 I know that D3 is capable of brush-based continuous updating as Mike has done in this example ; 我知道D3能够像Mike 在此示例中所做的那样基于笔刷进行连续更新; what part of that code have I missed in my adaptation? 在改编中我错过了代码的哪一部分?

Here's the function that I currently use to do the updating: 这是我当前用来进行更新的功能:

function brushended() {
  path.select('.donutPath')
    .data(pie([brush.extent()[1],100 - brush.extent()[1]]))
  .enter().append("path")
    .attr("fill", function(d, i) { return color(i); })
    .attr("d", arc);
  }

The event you need to listen to is .on("brush",... , like: 您需要听的事件是.on("brush",... ,例如:

var brush = d3.svg.brush()
    .x(x)
    .extent([0,40])
    .on("brush", brushended);

You should change the name of the function to better reflect the situation, but this alone will make it work. 您应该更改函数的名称以更好地反映情况,但是仅此一项就可以使它起作用。

FIDDLE with the listener changes, but also with changes to the way the update selection was being handled. 与侦听器一起更改的FIDDLE ,也与处理更新选择的方式发生更改的FIDDLE

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

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