【问题标题】:DC.js | How can I trigger my D3 updates?DC.js |如何触发我的 D3 更新?
【发布时间】:2017-05-03 12:18:13
【问题描述】:

我正在使用一些 D3 代码来整理我的 DC 箱线图,例如使 circle.outlier 半径更小,在每个箱线图后面插入一个矩形并附加一个悬停标题。

这在页面加载时效果很好。我希望它也可以用于过滤。它适用于一种过滤,而不适用于另一种过滤。

我在同一个仪表板上有一个直方图,并且使用 .brushOn(true),我有一个事件,它可以正确更新过滤器上的箱线图:

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

这段代码调用了下面的函数,该函数又调用了两个函数: (1) updateFactorFields2,它通过一个 fakegroup 更新箱线图后面的数据,并且似乎可以工作。和 (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
}

但 tidyBoxPlots 在以下触发时不起作用,即使调用 update() 并且 updateFactorFields 起作用:

$("[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

我在下拉菜单中使用了 selected.js,因此使用了 jquery。

谁能帮忙?

谢谢

【问题讨论】:

    标签: d3.js dc.js


    【解决方案1】:

    对于遇到相同问题的其他人:问题在于获取正确的事件类型以及在相对于 dc.renderAll() 的正确位置调用 update();

    【讨论】:

    • 感谢您的跟进。什么是正确的事件类型?
    • 这只是 postRender,但我不得不在调用 .render() 后交换一些代码行来获取它
    猜你喜欢
    • 2015-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-10
    • 1970-01-01
    • 1970-01-01
    • 2018-08-22
    相关资源
    最近更新 更多