在d3中按时间间隔对日志文件数据进行分组 [英] Group log file data by time interval in d3
问题描述
我有一些要绘制的日志文件数据.对于一个日志文件,每次发生事件时,都会在日志文件中添加一行.我可以得到它,以便数据看起来像这样:
I have some log file data that I would like to graph. For one log file, every time an event happens a line is added to the log file. I can get it so that the data looks like this:
data = [
{
"click": true,
"date": "2013-06-23T14:37:27.000Z"
},
{
"click": true,
"date": "2013-06-23T14:36:02.000Z"
},
...
...
...
]
现在,我想做的是在时间轴上查看此数据,这样我就可以了解一段时间内发生了多少点击.但是,我认为我需要按时间间隔(1分钟或15分钟,每天...)对数据进行分组,以便可以看到一段时间内有多少人点击.然后绘制间隔数据的图形.
Now, what I would like to do is view this data on a time line, so I can see how many clicks happen over time. However, I think I need to group this data by intervals (1 minute or 15 minute, day...) so that I can see how many people are clicking over a period of time. Then graph the interval data.
是否有按时间间隔对数据进行分组的方法? d3有办法做到这一点吗?我也在用人力车和咖啡脚本.
Is there a way to group data by time interval? Does d3 have a way to do this? I am also using rickshaw and coffeescript.
推荐答案
如Adam Pearce所建议,您可以在此处获取所有信息: http://bl.ocks.org/mbostock/3048166
As suggested by Adam Pearce, you can get all information here: http://bl.ocks.org/mbostock/3048166
第一步是定义x
:
var x = d3.scale.linear()
.domain([0, 120])
.range([0, width]);
然后,您只需定义所需的刻度数:
Then, you just define the number of ticks you want:
// Generate a histogram using twenty uniformly-spaced bins.
var data = d3.layout.histogram()
.bins(x.ticks(20))
(values);
values
的定义如下:
// Generate a log-normal distribution with a median of 30 minutes.
var values = d3.range(1000).map(d3.random.logNormal(Math.log(30), .4));
因此,秘诀在于 d3.layout.histogram().bins
以及 axis.ticks
调用.
So, the secret is behind the d3.layout.histogram().bins
and the axis.ticks
calls.
这篇关于在d3中按时间间隔对日志文件数据进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!