dc.js图表​​的.on函数显示错误 [英] .on function for dc.js charts showing error

查看:54
本文介绍了dc.js图表​​的.on函数显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我陷入了困境

dcCharts  = d3.selectAll("div.mychart") 
            .attr("class", "yourchart") 
            .each(function (d, i) { 
            return d ; 
         });

我检索div并执行以下操作:
`

I retrieve the divs and do this: `

 _.each(dcCharts, function (dcChart) {
    dcChart.on("filtered", function (chart, filter) {
        map.eachLayer(function (layer) {
        map.removeLayer(layer)
        }); 
    drawMap();
    });
    dc.renderAll();
});

我收到此错误:

Uncaught TypeError: dcChart.on is not a function
    at updateFile:229
    at Function.m.each.m.forEach (underscore-min.js:5)
    at updateFile:228
    at Object.<anonymous> (d3.v3.js:1996)
    at Object.event (d3.v3.js:504)
    at XMLHttpRequest.respond (d3.v3.js:1949)


推荐答案

对于将来的读者,这是为dc.js创建动态div并实现交叉过滤的仪表板,它提供了一些上下文

For future readers, this is a follow-up to Dynamic div creation for dc.js and implementing crossfiltered dashboard which provides some context.

这里的问题是每个 div 的绑定数据是字符串列名称,而不是图表。如果要生成图表数组,建议在初始化图表时构建该数组。 (摘自我对上一个问题的修改后的答案)

The issue here is that the bound data for each div is the string column name, not the chart. If you want to produce an array of charts, I recommend building the array while initializing the charts. (copied from my edited answer to the previous question)

var dcCharts = new Array(cols.length);
divs.each(function(col, i) {
  var dimension = cf.dimension(function(d) { return d[col]; });
  var group = dimension.group(); // or however you want to bin them
  var bar = dc.barChart(this) // pass div element as parent/root instead of using selector
      .dimension(dimension)
      .group(group)
      // ...
  dcCharts[i] = bar;
});

现在您的 _。each(dcCharts,... 应该可以。

这篇关于dc.js图表​​的.on函数显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆