You can use a quick search for the properties of a JavaScript object as an index when accumulating your accounts:
var counts = {}; rows.forEach(function(r) { if (!counts[r.Day]) { counts[r.Day] = 0; } counts[r.Day]++; });
Then you will need to convert this back to an array so you can use it with D3:
var data = []; Object.keys(counts).forEach(function(key) { data.push({ day: key, count: counts[key] }); });
I assume that you want to ignore the What column because you were only talking about combining the number of days, and there are different values โโof What on the same day. If you want to consider the โWhatโ while you are calculating, you can simply create it in the key of your original object counts ( r.Day + r.What ).
EDIT: based on the comment add code with a composite key.
var counts = {}; rows.forEach(function(r) { var key = r.Day + r.What; if (!counts[key]) { counts[key] = { day: r.Day, what: r.What, count: 0 }; } counts[key].count++; }); var data = []; Object.keys(counts).forEach(function(key) { data.push(counts[key]); });
source share