سؤال

The following code rounds up a data series and sums up amounts with a minute interval.

   var nested_data = d3.nest()
   .key(function(d) {return d3.time.minute(d.date)})
   .rollup(function(a) {return d3.sum(a, function(d) {return d.amount})})
   .entries(data); 

However, is there a way to have a custom interval of say 5 minutes? Perhaps using a range with a step ?

هل كانت مفيدة؟

المحلول

This appears to do it:

  var coeff = 1000 * 60 * 5;
   var nested_data = d3.nest()
  .key(function(d) { return new Date(Math.round(d.date.getTime() / coeff) * coeff)})
  .rollup(function(a) {return d3.sum(a, function(d) {return d.amount})})
  .entries(data); 
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top