jQuery Flot: 24 hour axis

a 夏天 提交于 2019-12-08 02:23:38

问题


I'm using jQuery Flot plugin and I would like to have 24 hour x-axis. But how to accomplish that? I included necessary time plugin (jquery.flot.time.js) and tried something like this:

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

but nothing is showing up. What am I doing wrong?


回答1:


You are looking for something like this:

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
},

Very contrived example here.

EDITS

To show last 24 hours use:

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
},

Updated fiddle.



来源:https://stackoverflow.com/questions/21386487/jquery-flot-24-hour-axis

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!