未捕获的TypeError:无法读取未定义的属性“选择”

时间:2019-04-24 08:40:59

标签: javascript chart.js crossfilter

我正在运行用于绘制条形图的交叉过滤器代码。在图表上选择条形图时,出现类似

的错误
  

pie-chart.js:304未捕获的TypeError:无法读取未定义的属性“域”

AND

  

pie-chart.js:304未捕获的TypeError:无法读取未定义的属性“ select”

但是,我什至没有饼图。当我尝试查找所引用的文件时,它为空。.因此,基本上不存在pie-chart.js,并且我也找不到它的代码。

我不确定该怎么做。

可在此提琴https://jsfiddle.net/pcer32tb/

中找到代码
<script>
var data = [
  {"key":"KEY-1","tags":["tag1", "tag2"], "date":new Date("10/02/2012")},

  {"key":"KEY-2","tags":["tag2"], "date": new Date("10/05/2012")},

  {"key":"KEY-3","tags":["tag3", "tag1"], "date":new Date("10/08/2012")}];

function reduceAdd(p, v) {
  v.tags.forEach (function(val, idx) {
    p[val] = (p[val] || 0) + 1; //increment counts
  });
  return p;
}

function reduceRemove(p, v) {
  v.tags.forEach (function(val, idx) {
    p[val] = (p[val] || 0) - 1; //decrement counts
  });
  return p;

}

function reduceInitial() {
  return {};  
}

var cf = crossfilter(data);

var tags = cf.dimension(function(d){ return d.tags;});
var tagsGroup = tags.groupAll().reduce(reduceAdd, reduceRemove, reduceInitial).value();

// hack to make dc.js charts work
tagsGroup.all = function() {
  var newObject = [];
  for (var key in this) {
    if (this.hasOwnProperty(key) && key != "all") {
      newObject.push({
        key: key,
        value: this[key]
      });
    }
  }
  return newObject;
}

var dates = cf.dimension(function(d){ return d.date;});
var datesGroup = dates.group();


var chart = dc.rowChart("#chart");
chart                                                                                       
  .renderLabel(true)
  .dimension(tags)
  .group(tagsGroup)
  .filterHandler(function(dimension, filter){     
  dimension.filter(function(d) {return chart.filter() != null ? d.indexOf(chart.filter()) >= 0 : true;}); // perform filtering
  return filter; // return the actual filter value
})
  .xAxis().ticks(3);

var chart2 = dc.barChart("#chart2");
chart2  
  .width(500)
  .transitionDuration(800)
//.margins({top: 10, right: 50, bottom: 30, left: 40})
  .dimension(dates)
  .group(datesGroup)
  .elasticY(true)
  .elasticX(true)
  .round(d3.time.day.round)    
  .x(d3.time.scale())    
  .xUnits(d3.time.days)
  .centerBar(true)
  .renderHorizontalGridLines(true)       
  .brushOn(true);    


dc.renderAll();

0 个答案:

没有答案