newarray = [{Date_Reported: 2020-5-1, Zone: Edmonton, Count: (#of entries that match date and zone)},{Date_Reported: 2020-5-1, Zone: Calgary, Count: (#ofentries)}…]
Combining entries of the same date and zone and increasing the count value for each one found. I have tried for loops, and foreach with if statements with little success and was wondering if there is a more efficient way of approaching this?
I looked at group and at rollup and rollups but they either create maps or nested arrays while the visualization functions always use d.objectname to reference array values…
So far data2 = d3.flatRollup(data, v => v.length, d => d.Date_reported, d => d.Zone)
gets me the closest with an array of arrays with the third index being the count I need but I am unsure of how to convert the array of arrays into just an array of objects with keys for the values…
Thank you Fil for putting me one step closer.
Figured it out, for anyone that finds this once you use flatRollup just use another map function with get like this:
This actually didn’t work because I assign the count value without reducing all the dates to one entry… fml
Ok I figured out how to format my data:
Steps:
1)
data2 = d3.flatRollup(data, v => v.length, d => d.Date_reported, d => d.Zone)
2)
datamap = data2.map((d,i) => ({
Date: data2[i][0],
Zone: data2[i][1],
Count: data2[i][2]