我试图每月制作一个数据计数条形图,数据如下:
[
{
"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>
这是使用&#39; angular-dc&#39;模块
答案 0 :(得分:1)
reduceCount
只是给出了记录数量的计数。它不需要访问器,因此您的$log
永远不会被调用。我相信你正在寻找reduceSum
。