Flot时间插件基于Javascript时间戳。Javascript时间戳是自1970年1月1日00:00:00 UTC以来的毫秒数。您需要将时间戳(当前以秒为单位)乘以1000才能正确显示所有内容。
我的图上有以下几点:
data = [
[1450825200, 3],
[1450828800, 9],
[1450832400, 8],
[1450836000, 7],
[1450839600, 6]
];
第一个值(data[0][0])
是时间戳,第二个值(data[0][1])
是点击量。根据这个转换器,在我的时区GMT+1:00,第一个1450825200
等于当前日期和12:00 AM,数组中的下一个时间戳(1450828800
)为下午1:00,第三个为下午2:00,等等。
但根据flotcharts,我所有的时间戳都代表晚上7点。当我悬停在点上时,每个点都显示19:00,我的x轴就不见了(因为tickSize设置为1小时,没有其他小时)。
我以这种方式初始化图形:
$.plot('#graphDashboard', dataSet, // dataSet[0] contains data example I've shown above
{
plot: true,
xaxes: [{
mode: "time", timeformat: "%H:%M",
tickSize: [1, "hour"]
}],
yaxes: [{
position: 'left',
tickFormatter: function (val, axis) {
return val.toLocaleString();
}
},
{
position: 'left',
autoscaleMargin: 0.2,
tickFormatter: function (val, axis) {
return val.toLocaleString();
}
}
],
tooltipOpts: {
content: "%s (%x, %y)",
shifts: {
x: -100,
y: -50
},
dateFormat: "%H:%M",
defaultTheme: false
},
series: {
stack: false,
lines: {
show: true,
fill: false
}
},
legend: {
show: false
}
});