time series

39 views
Skip to first unread message

Mike B

unread,
Feb 15, 2010, 5:22:03 PM2/15/10
to Flotr Javascript Plotting Library
Hello. I've got some data collected every 30 seconds resulting in a
data series like this:

[00:58:19, 2732],
[00:58:49, 2705],
[00:59:19, 2811]

or alternatively, like this:

[2010-02-15 00:58:19, 2732],
[2010-02-15 00:58:49, 2705],
[2010-02-15 00:59:19, 2811]

but of course this won't fly. Can anyone suggest a way to get this to
work in Flotr? I'm hoping timeFormat or mode:time might be able to
help. Any guidance would be greatly appreciated.

Thanks very much,
MikeB

oughton

unread,
Feb 15, 2010, 5:34:28 PM2/15/10
to Flotr Javascript Plotting Library
That data format is fine, except your time format needs to be a UTC
timestamp (in milliseconds).

Use the option:
mode: "time"

and you should be away.

So your data should look like for example:

[1266195499000, 2732],
[1266195529000, 2705],
[1266195559000, 2811]

Remember that you data needs to be in the format:

[ data: [ [x0, y0], [x1, y1] ... ] ] ]

Message has been deleted
Message has been deleted

Mike B

unread,
Feb 17, 2010, 4:20:08 PM2/17/10
to Flotr Javascript Plotting Library
Thanks for the reply, it works just as described. The time is
currently displayed on the axis ticks in the 24-hour time format.
However, the mouse tracker shows the UTC value.

Do you know if it's possible to show both axis tick and mouse tracker
like this: 2010-02-15 12:25:56? Here's my current formatter (see
below). It blows up on the second line, returning
"datatime.getMilliseconds is not a function"; if I comment out that
line I get NaNs returned, like so: "NaN-NaN-NaN-NaN NaN:NaN:NaN".

Any additional help would be greatly appreciated. Thanks!

function testdatestamp(datatime) {
var datatime = datatime-datatime.getMilliseconds();
var localedatatime = new Date(datatime);
var year=localedatatime.getFullYear();
var month=localedatatime.getMonth()+1;
var day=localedatatime.getDate();
var hour=localedatatime.getHours();
var minute = localedatatime.getMinutes();
var second = localedatatime.getSeconds();
if (month < 10) {
month = "0"+month;
}
if (day < 10) {
day = "0"+day;
}
if (hour < 10) {
hour = "0"+hour;
}
if (minute < 10) {
minute = "0"+minute;
}
if (second < 10) {
second = "0"+second;
}
var v = year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
return v;

Mike B

unread,
Feb 17, 2010, 4:48:27 PM2/17/10
to Flotr Javascript Plotting Library
This has been solved. I figure I'd post my kludgy fix here in case
anyone else needs it:

function testdatestamp(x) {
var localedatatime = new Date(x*1000);


var year=localedatatime.getFullYear();
var month=localedatatime.getMonth()+1;
var day=localedatatime.getDate();
var hour=localedatatime.getHours();
var minute = localedatatime.getMinutes();
var second = localedatatime.getSeconds();
if (month < 10) {
month = "0"+month;
}
if (day < 10) {
day = "0"+day;
}
if (hour < 10) {
hour = "0"+hour;
}
if (minute < 10) {
minute = "0"+minute;
}
if (second < 10) {
second = "0"+second;
}
var v = year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
return v;

//return myDate.toLocaleString();

Reply all
Reply to author
Forward
0 new messages