我试图了解如何在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。
答案 0 :(得分:2)
普通的crossfilter组根据关键功能有多个bin。
如果您想要计算所有记录而不对其进行分组,请尝试使用groupAll代替:
var numRecords = cf.groupAll();
numberDisplayElem
.group(numRecords)
.valueAccessor(x => x);