2016-03-15 70 views
0

我試圖讓數據的條形圖每個月算crossfilter順序,數據看起來如下:通過計數

[ 
    { 
    "key_as_string": "2013-11-01T00:00:00.000Z", 
    "key": 1383264000000, 
    "doc_count": 1, 
    "dd": "2013-11-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2013-12-01T00:00:00.000Z", 
    "key": 1385856000000, 
    "doc_count": 0, 
    "dd": "2013-12-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2014-01-01T00:00:00.000Z", 
    "key": 1388534400000, 
    "doc_count": 0, 
    "dd": "2014-01-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2014-02-01T00:00:00.000Z", 
    "key": 1391212800000, 
    "doc_count": 2, 
    "dd": "2014-02-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2014-03-01T00:00:00.000Z", 
    "key": 1393632000000, 
    "doc_count": 15, 
    "dd": "2014-03-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2014-04-01T00:00:00.000Z", 
    "key": 1396310400000, 
    "doc_count": 20, 
    "dd": "2014-04-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2014-05-01T00:00:00.000Z", 
    "key": 1398902400000, 
    "doc_count": 8, 
    "dd": "2014-05-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2014-06-01T00:00:00.000Z", 
    "key": 1401580800000, 
    "doc_count": 5, 
    "dd": "2014-06-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2014-07-01T00:00:00.000Z", 
    "key": 1404172800000, 
    "doc_count": 10, 
    "dd": "2014-07-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2014-08-01T00:00:00.000Z", 
    "key": 1406851200000, 
    "doc_count": 0, 
    "dd": "2014-08-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2014-09-01T00:00:00.000Z", 
    "key": 1409529600000, 
    "doc_count": 11, 
    "dd": "2014-09-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2014-10-01T00:00:00.000Z", 
    "key": 1412121600000, 
    "doc_count": 17, 
    "dd": "2014-10-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2014-11-01T00:00:00.000Z", 
    "key": 1414800000000, 
    "doc_count": 7, 
    "dd": "2014-11-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2014-12-01T00:00:00.000Z", 
    "key": 1417392000000, 
    "doc_count": 7, 
    "dd": "2014-12-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2015-01-01T00:00:00.000Z", 
    "key": 1420070400000, 
    "doc_count": 17, 
    "dd": "2015-01-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2015-02-01T00:00:00.000Z", 
    "key": 1422748800000, 
    "doc_count": 10, 
    "dd": "2015-02-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2015-03-01T00:00:00.000Z", 
    "key": 1425168000000, 
    "doc_count": 5, 
    "dd": "2015-03-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2015-04-01T00:00:00.000Z", 
    "key": 1427846400000, 
    "doc_count": 2, 
    "dd": "2015-04-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2015-05-01T00:00:00.000Z", 
    "key": 1430438400000, 
    "doc_count": 5, 
    "dd": "2015-05-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2015-06-01T00:00:00.000Z", 
    "key": 1433116800000, 
    "doc_count": 3, 
    "dd": "2015-06-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2015-07-01T00:00:00.000Z", 
    "key": 1435708800000, 
    "doc_count": 14, 
    "dd": "2015-07-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2015-08-01T00:00:00.000Z", 
    "key": 1438387200000, 
    "doc_count": 5, 
    "dd": "2015-08-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2015-09-01T00:00:00.000Z", 
    "key": 1441065600000, 
    "doc_count": 10, 
    "dd": "2015-09-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2015-10-01T00:00:00.000Z", 
    "key": 1443657600000, 
    "doc_count": 10, 
    "dd": "2015-10-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2015-11-01T00:00:00.000Z", 
    "key": 1446336000000, 
    "doc_count": 15, 
    "dd": "2015-11-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2015-12-01T00:00:00.000Z", 
    "key": 1448928000000, 
    "doc_count": 6, 
    "dd": "2015-12-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2016-01-01T00:00:00.000Z", 
    "key": 1451606400000, 
    "doc_count": 18, 
    "dd": "2016-01-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2016-02-01T00:00:00.000Z", 
    "key": 1454284800000, 
    "doc_count": 15, 
    "dd": "2016-02-01T00:00:00.000Z" 
    }, 
    { 
    "key_as_string": "2016-03-01T00:00:00.000Z", 
    "key": 1456790400000, 
    "doc_count": 4, 
    "dd": "2016-03-01T00:00:00.000Z" 
    } 
] 

然後我執行下列操作:

var ndx = crossfilter(data); 

$scope.dimension = ndx.dimension(function (d) { 
    return d.key; 
}); 

$scope.orderdbycount = $scope.dimension.group().reduceCount(function(d) { 
    if (d.doc_count > 1) { 
     $log.debug(d); 
    } 
    return d.doc_count; 
}); 
$scope.scale = d3.time.scale().domain([$scope.dimension.top(1)[0].dd, $scope.dimension.bottom(1)[0].dd]); 

但沒有什麼是每記錄一次;我orderbyCount有1

唯一的價值是我在做的HTML如下:

<div dc-chart="barChart" 
     dc-width="700" 
     dc-height="150" 
     dc-name="'volumeChart2'" 
     dc-dimension="dimension" 
     dc-group="orderdbycount" 
     dc-x="scale" 
     dc-x-units="d3.time.months"></div> 

這是與「角-DC」模塊

回答

1

reduceCount只是給你的計記錄數。它不需要訪問器,因此您的$log永遠不會被調用。我相信你正在尋找reduceSum

+0

就是這樣;謝謝! – Kiwi