jQuery Flot:24小时轴

时间:2014-01-27 16:43:12

标签: javascript flot

我正在使用jQuery Flot plugin,我希望有24小时的x轴。但是如何实现呢?我包括了必要的时间插件(jquery.flot.time.js)并尝试过这样的事情:

xaxis: {
    mode: "time",
    timeformat: "%H",
    tickSize: [1, "day"],
    twelveHourClock: true
}

但没有任何表现。我做错了什么?

1 个答案:

答案 0 :(得分:8)

你正在寻找这样的东西:

xaxis: {
    mode: "time",
    timeformat: "%I:%M %p", // HH:MM am/pm
    tickSize: [1, "hour"], // tick every hour
    twelveHourClock: true,
    min: 1390780800000, // start of today
    max: 1390863600000 // end of today
},

非常人为的例子here

enter image description here

<强> EDITS

要显示过去24小时,请使用:

var epochT = (new Date).getTime(); // time right now in js epoch

$.plot($("#placeholder"), [data], {
xaxis: {
    mode: "time",
    timeformat: "%I:%M %p",
    tickSize: [1, "hour"],
    twelveHourClock: true,
    min: epochT - 86400000, // time right now - 24 hours ago in milliseonds
    max: epochT,
    timezone: "browser" // switch to using local time on plot
},

更新了fiddle