Time series rounded to 15 minute intervals?

989 views
Skip to first unread message

Bradley Spatz

unread,
Jun 29, 2015, 1:01:48 PM6/29/15
to dc-js-us...@googlegroups.com
I'm using dc.lineChart to visualize a time series which may have multiple records per second:

20150615T040007Z,[value]
20150615T040007Z,[value]
20150615T040009Z,[value]

I'm able to graph by the minute or hour using:

var dtDim = facts.dimension(function(d) { return d3.time.minute(d.DateTime); });
var dtDim = facts.dimension(function(d) { return d3.time.hour(d.DateTime); });

But I wondered how to (easily -- that's usually the rub, eh?) graph by15-minute intervals?  It looks like d3 contemplates this (Bostock, you are impressive) but I couldn't see how exactly.  So hence my question to you all.

Thanks in advance.

Gordon Woodhull

unread,
Jul 1, 2015, 3:53:22 PM7/1/15
to dc.js user group
Crossfilter dimension by minutes, then group by 15 minutes:

var dtDim = facts.dimension(function(d) { return d3.time.minute(d.DateTime); });
var min15group = dtDim.group(function(x) { return x.getMinutes()/15;}
--
You received this message because you are subscribed to the Google Groups "dc-js user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dc-js-user-gro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dc-js-user-group/92b2e5a3-c56c-4cb5-954b-de0163971dca%40googlegroups.com.

Gordon Woodhull

unread,
Jul 4, 2015, 2:45:51 PM7/4/15
to dc-js-us...@googlegroups.com
Okay, that wasn't quite enough. Even with rounding, this would only group by 15-minute intervals but discard the rest of the date (putting all hours in the same bucket).

The right way to do this is to use d3.time.interval, but it's not exposed:

Still, until that gets resolved, we can copy that code and use it. Here is a generalization of d3.time.minute
for multi-minute intervals, using d3_time_interval:

function n_minutes_interval(nmins) {
    var denom = 6e4*nmins;
    return d3_time_interval(function(date) {
      return new d3_date(Math.floor(date / denom) * denom);
    }, function(date, offset) {
      date.setTime(date.getTime() + Math.floor(offset) * denom); // DST breaks setMinutes
    }, function(date) {
      return date.getMinutes();
    });
}


Gordon Woodhull

unread,
Jul 5, 2015, 7:10:58 AM7/5/15
to dc-js-us...@googlegroups.com
Also it looks like going forward, in d3-time (d3 4.0) there is interval.filter:


And d3.time.interval may be exposed as it is:



On Jul 4, 2015, at 2:45 PM, Gordon Woodhull <gor...@woodhull.com> wrote:

Okay, that wasn't quite enough. Even with rounding, this would only group by 15-minute intervals but discard the rest of the date (putting all hours in the same bucket.

The right way to do this is to use d3.time.interval, but it's not exposed:

Still, until that gets resolved, we can copy that code and use it. Here is a generalization of d3.time.minute for multi-minute intervals, using d3_time_interval:

function n_minutes_interval(nmins) {
    var denom = 6e4*nmins;
    return d3_time_interval(function(date) {
      return new d3_date(Math.floor(date / denom) * denom);
    }, function(date, offset) {
      date.setTime(date.getTime() + Math.floor(offset) * denom); // DST breaks setMinutes
    }, function(date) {
      return date.getMinutes();
    });
}


--
You received this message because you are subscribed to the Google Groups "dc-js user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dc-js-user-gro...@googlegroups.com.

Bradley Spatz

unread,
Jul 18, 2015, 7:12:30 AM7/18/15
to dc-js-us...@googlegroups.com
Thank you Gordon for confirming .interval and the thorough research and example!
Reply all
Reply to author
Forward
0 new messages