DC.js numberDisplay与crossfilter获取总记录

我想了解如何在dc.js中使用crossfilter。 我有以下数据,我只想通过用数据内的对象总数填充numberDisplay开始。 然后再填充有多少记录用于票据损失。

var data = [
  {
    "team": "bills",
    "location": "home",
    "outcome": "loss"
  },
  {
    "team": "dolphins",
    "location": "away",
    "outcome": "loss"
  },
  {
    "team": "jets",
    "location": "home",
    "outcome": "loss"
  },
  {
    "team": "jets",
    "location": "home",
    "outcome": "win"
  },
  {
    "team": "dolphins",
    "location": "home",
    "outcome": "loss"
  },
  {
    "team": "dolphins",
    "location": "away",
    "outcome": "win"
  },
  {
    "team": "dolphins",
    "location": "home",
    "outcome": "win"
  },
  {
    "team": "dolphins",
    "location": "away",
    "outcome": "loss"
  }
]

DC.JS numberDisplay需要一个组,但我一直无法弄清楚如何简单计算开始的记录数。

var cf = crossfilter(data);
var team = cf.dimension(function(d) { return d.team })
var teams = team.group().reduceCount();

这似乎只返回第一个键的值? reduceSum()和groupAll()也没有工作。

var numberDisplayElem = dc.numberDisplay("#number-display-elem");
    numberDisplayElem
        .group(teams);

基本上只是试图让总数填充numberDisplay,然后是单个数字的过滤值,比如总账单损失等。无法入门。 TIA。


普通的交叉过滤器组具有基于关键功能的多个箱。

如果您想对所有记录进行计数而不分箱,请尝试使用groupAll:

var numRecords = cf.groupAll();
numberDisplayElem
  .group(numRecords)
  .valueAccessor(x => x);
链接地址: http://www.djcxy.com/p/32723.html

上一篇: DC.js numberDisplay with crossfilter get total records

下一篇: Efficient way to plot area normalized bar chart using crossfilter / dc.js?