最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery Flot: 24 hour axis - Stack Overflow

programmeradmin1浏览0评论

I'm using jQuery Flot plugin and I would like to have 24 hour x-axis. But how to acplish 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?

I'm using jQuery Flot plugin and I would like to have 24 hour x-axis. But how to acplish 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?

Share Improve this question asked Jan 27, 2014 at 16:43 IndyIndy 4,9577 gold badges26 silver badges35 bronze badges 3
  • What do you mean by a "24 hour x-axis"? One that is limited to just 24 hours? How would the ticks be labeled, etc...? – Mark Commented Jan 27, 2014 at 16:54
  • I want to have on x-asix time every 1 hour (24-hour clock), like this: 00:00, 01:00, 02:00 etc. – Indy Commented Jan 27, 2014 at 17:03
  • 1 Wouldn't you want to use tickSize: [1, "hour"] instead of "day"? – mechenbier Commented Jan 27, 2014 at 17:33
Add a ment  | 

1 Answer 1

Reset to default 9

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.

发布评论

评论列表(0)

  1. 暂无评论