jquery flot xaxis时间

时间:2010-03-24 11:33:53

标签: jquery flot

在这个例子中,xaxis将比较日期......

$.plot($("#placeholder"), data, {
                yaxis: {},
                xaxis: { mode: "time",minTickSize: [1, "day"],timeformat: "%d/%m/%y"},"lines": {"show": "true"},"points": {"show": "true"},clickable:true,hoverable: true
            });

我如何打印时间?

这是我想要的结果:

22:00 23:00 00:00 01:00 02:00 ...... 23:00 00:00 01:00 02:00 .... 06:00

有可能吗?

2 个答案:

答案 0 :(得分:57)

来自Api Flot官方文件:(见https://github.com/flot/flot/blob/master/API.md

  xaxis: {
    mode: "time",
    timeformat: "%y/%m/%d"
  }

这将导致刻度标签如“2000/12/24”。下列 支持说明符

 %h: hours
  %H: hours (left-padded with a zero)
  %M: minutes (left-padded with a zero)
  %S: seconds (left-padded with a zero)
  %d: day of month (1-31), use %0d for zero-padding
  %m: month (1-12), use %0m for zero-padding
  %y: year (2 digits)
  %Y: year (4 digits)
  %b: month name (customizable)
  %p: am/pm, additionally switches %h/%H to 12 hour instead of 24
  %P: AM/PM (uppercase version of %p)

答案 1 :(得分:20)

$.plot($("#placeholder"), data, {
        yaxis: {
        },
        xaxis: { mode: "time",minTickSize: [1, "hour"],
                min: (new Date("2000/01/01")).getTime(),
                max: (new Date("2000/01/02")).getTime()
},
        "lines": {"show": "true"},
        "points": {"show": "true"},
        clickable:true,hoverable: true
});

将此作为起点,您可以在此处查看结果http://jsfiddle.net/UEePE/