My json data consists of timestamps like:
[{"Time":"2017-02-07 16:14:06"},
{"Time":"2017-02-07 16:58:49"},
{"Time":"2017-02-07 17:07:11"},
{"Time":"2017-02-07 18:13:19"},
{"Time":"2017-02-07 13:56:06"},
{"Time":"2017-02-07 19:07:57"},
{"Time":"2017-02-07 12:08:58"},
{"Time":"2017-02-07 01:41:00"},
{"Time":"2017-02-07 11:56:49"},
{"Time":"2017-02-07 02:45:29"},
{"Time":"2017-02-07 11:40:07"},
{"Time":"2017-02-07 04:15:45"},
]
To convert these into 24-hour values, I use the following d3.json function with a parsing mechanism:
var parseDate = d3.time.format("%Y-%m-%d %H:%M:%S").parse;
d3.json("/wp-content/themes/jordan/js/data.json", function(d){
d.forEach(function(d){
d.Time = parseDate(d.Time).getHours();
console.log(d.Time);
});
});
After obtaining integer representations of hours, I am now looking to group these values into 4-hour increments using d3.nest()
. For example, I want to group them as follows: 0 - 4, 4 - 8, 8 - 12, 12 - 16, 16 - 20, 20 - 24. How can I achieve this using d3.nest()?