2017-05-03 45 views
1

我正在使用一些D3代码来整理我的DC盒子,例如使circle.outlier半径更小,在每个boxplot后面插入一个矩形并附加悬停标题。DC.js |我怎样才能触发我的D3更新?

这适用于页面加载。我也希望它能够过滤。它适用于一种过滤而不是另一种过滤。

我有相同的仪表盘上的柱状图,并与.brushOn(真),我有一个事件,它正确地更新过滤器上的箱线图:

.on("filtered", function(obj){ update(); }); 

此代码调用下面的函数,该函数调用还有两个函数:(1)updateFactorFields2,它通过一个假群更新箱图背后的数据,并且似乎有效。和(2)tidyBoxPlots,这是问题。

function update() { 

    var grps = window.grps;//an array holding my crossfilter groups 
    var dims = window.dims; //an array holding CF dimensions 

    updateFactorFields2(grps[0]); 

    factorBox.render();//factorBox is my DC boxplot chart 

    tidyBoxPlots('postRender'); 

} 

tidyBoxPlots也更新.title,但下面的代码已足够。 tidyBoxPlots最终由histChart.on(“filtered”,...)触发时起作用。

function tidyBoxPlots(evType) { 

    d3.selectAll("circle.outlier").attr("r","2");//works in one case and not another 
    d3.selectAll("g.box").insert("rect","line.center").attr("x","0").attr("y","0").attr("width","8").attr("height","102.5").attr("class","boxHover");//ditto 
} 

但当由以下触发,即使更新()被调用和updateFactorFields工作tidyBoxPlots不起作用:

$("[id='filterDropdown']").on('change',function(e,p){ 
     if (p.selected) { 
      var tempIndex = filters[0].indexOf(e.target.id); 
      filters[6][tempIndex].push(p.selected);//store this filter 
      filters[5][tempIndex].filterFunction(function(d){ return filters[6][tempIndex].indexOf(d)!=-1; });//filter the dimension stored in filters[5] by the array values stored in filters[6] 
      update();//calls update() fine 

     } 

我敢肯定,问题是事件型我正在使用,因为我以前遇到过麻烦。所以,我试过最如果不是所有的这些,但没有喜悦的:

http://dc-js.github.io/dc.js/docs/html/dc.baseMixin.html#on

我使用chosen.js我的下拉菜单,因此jQuery的。

任何人都可以帮忙吗?

感谢

回答

1

为了其他人同样的问题:这个问题是找到合适的事件类型加上调用update()的位置相对于dc.renderAll权();

+0

感谢您的跟进。什么是正确的事件类型? – Gordon

+0

这只是postRender,但我必须交换一些代码行才能在调用.render()之后得到它。 – emma