在crossfilter.js中过滤两次会产生不一致的结果

时间:2015-08-28 16:28:07

标签: crossfilter

我正在处理学校调查的数据。数据具有性别,等级和答案属性。最终,我希望能够显示一个分组的条形图,观众可以看到男孩和女孩的答案。要获取我使用crossfilter.js过滤的数据,首先使用针对男孩的过滤器,然后使用针对女孩的过滤器。因为我得到了不一致的结果,我可能会做错事。可能我错过了关于crossfilter.js哲学的一些观点。我想知道我的实现是否正确,或者我是否应该以不同的方式使用crossfilter。

请注意,问题由其索引(B-13)

编码
<html>
<head>
    <meta charset="UTF-8">
    <title>Prueba con crossfilter</title>
    <script type = "text/javascript" src = "../static/crossfilter.js"></script>
    <script type = "text/javascript" src  = "../static/d3.js"></script>
</head>
<body>
    <script>
    var data =[{"grado": 6, "Sexo": 1, "B-13": 3},
    {"grado": 6, "Sexo": 2, "B-13": 3},
    {"grado": 6, "Sexo": 2, "B-13": 1},
    {"grado": 6, "Sexo": 1, "B-13": 3},
    {"grado": 6, "Sexo": 2, "B-13": 3},
    {"grado": 6, "Sexo": 2, "B-13": 5},
    {"grado": 6, "Sexo": 2, "B-13": 3},
    {"grado": 6, "Sexo": 1, "B-13": 3},
    {"grado": 6, "Sexo": 2, "B-13": 3},
    {"grado": 6, "Sexo": 2, "B-13": 5},
    {"grado": 6, "Sexo": 2, "B-13": 3},
    {"grado": 6, "Sexo": 2, "B-13": 3},
    {"grado": 6, "Sexo": 2, "B-13": 3},
    {"grado": 6, "Sexo": 2, "B-13": 3},
    {"grado": 6, "Sexo": 1, "B-13": 5},
    {"grado": 6, "Sexo": 2, "B-13": 3},
    {"grado": 6, "Sexo": 2, "B-13": 2},
    {"grado": 6, "Sexo": 2, "B-13": 2},
    {"grado": 6, "Sexo": 1, "B-13": 2},
    {"grado": 6, "Sexo": 1, "B-13": 1},
    {"grado": 6, "Sexo": 2, "B-13": 3},
    {"grado": 6, "Sexo": 1, "B-13": 1},
    {"grado": 6, "Sexo": 2, "B-13": 4},
    {"grado": 6, "Sexo": 2, "B-13": 4},
    {"grado": 6, "Sexo": 2, "B-13": 3},
    {"grado": 7, "Sexo": 1, "B-13": 2},
    {"grado": 7, "Sexo": 2, "B-13": 1},
    {"grado": 7, "Sexo": 2, "B-13": 2},
    {"grado": 7, "Sexo": 1, "B-13": 1},
    {"grado": 7, "Sexo": 1, "B-13": 5}];


    // Crossfilter:
    cf = crossfilter(data);
    bySex = cf.dimension(function (d) { return d["Sexo"]; });
    byB13 = cf.dimension(function (d) { return d["B-13"]; });

    // Men
    bySex.filter("1"); 
    totalMen = cf.groupAll().value();
    console.log("Total men " + totalMen);

    menAnswers = byB13.group().top(Infinity);
    console.log(menAnswers);

    //Women
    bySex.filterAll();
    bySex.filter("2");
    totalWomen = cf.groupAll().value();
    console.log("Total women " + totalWomen);

    womenAnswers = byB13.group().top(Infinity);
    console.log(womenAnswers);


    </script>

</body>
</html>

0 个答案:

没有答案