Crossfilter.js按多个分类轴分组

时间:2015-09-07 20:13:42

标签: javascript dc.js crossfilter categorical-data

我有以下问题: 我的数据集如下所示:

[{
"id": 1542284,
"date": "2013-04-22",
"kilometer": 111179.364089776,
"country": "RU",
"ps": 100,
"model": "110A"
},
{
"id": 1542285,
"date": "2013-08-30",
"kilometer": 211963.649155722,
"country": "FR",
"ps": 110
"model": "110A"
},
{
"id": 1542286,
"date": "2013-03-07",
"kilometer": 163694.246231156,
"country": "DE",
"ps": 120
"model": "210B"}]

现在我想将dc.js与crossfilter.js一起使用来制作HEATMAP x轴:国家和 y轴:模型。 color属性将对应于组中的项目数:|(country x model)|

我现在的问题是如何使用两个分类轴制作crossfilter.js组语句?

var ndx = crossfilter(data);
var countryDimension = ndx.dimension(function (d){
    return d.country;
});

modelByCountryGroup = countryDimension.group().reduce(
    /* callback for when data is added to the current filter results */
    function (p, v) {
        ++p.count;
        //HOW DO I STORE/PROCESS v.model HERE
        return p;
    },
    /* callback for when data is removed from the current filter results */
    function (p, v) {
        --p.count;
        //HOW DO I STORE/PROCESS v.model HERE
        return p;
    },
    /* initialize p */
    function () {
        return {count: 0, WHATDOINEEDHERE};
    }
);

1 个答案:

答案 0 :(得分:3)

您可以创建组合维度吗?

var dim = ndx.dimension(function(d) { return d.country + ":" + d.model; });
var group = dim.group();

这将按国家/地区x型号提供您的计数,对吗?