I'm starting with dc and I'm turning around for several days about a simple thing I can't do. I've got a classical data sample of payments with this structure: {date: "2011-11-14T16:17:54Z", quantity: 2, total: 190, tip: 100, type: "tab"} I just want to display the number of different kind of types of payments. There are 3. I can display it in the console, but not in the the chart. I have tried lot of different things but none is working. I have something working with reduceSum, but not with reduceCount, the structure of the object seems to be different. Thanks for your help
This is my code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1"/>
<title>Crossfilter</title>
<script src="crossfilter.js"></script>
<script src="d3.js"></script>
<script src="dc.js"></script>
</head>
<body>
<div class="container">
My count :
<div id="category-count"></div>
<script type="text/javascript">
var payments = crossfilter([
{date: "2011-11-14T16:17:54Z", quantity: 2, total: 190, tip: 100, type: "tab"},
{date: "2011-11-14T16:20:19Z", quantity: 2, total: 190, tip: 100, type: "tab"},
{date: "2011-11-14T16:28:54Z", quantity: 1, total: 300, tip: 200, type: "visa"},
{date: "2011-11-14T16:30:43Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T16:48:46Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T16:53:41Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T16:54:06Z", quantity: 1, total: 100, tip: 0, type: "cash"},
{date: "2011-11-14T16:58:03Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T17:07:21Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T17:22:59Z", quantity: 2, total: 90, tip: 0, type: "tab"},
{date: "2011-11-14T17:25:45Z", quantity: 2, total: 200, tip: 0, type: "cash"},
{date: "2011-11-14T17:29:52Z", quantity: 1, total: 200, tip: 100, type: "visa"}
]);
var paymentsByType = payments.dimension(function(d) { return d.type; });
var countType = paymentsByType.group().reduceCount();
console.log(countType.size());
dc.numberDisplay('#category-count')
.formatNumber(d3.format("d"))
.group(countType)
.valueAccessor( function (d) { return d.size(); } );
</script>
</div>
</body>
</html>