Flot Js 上奇怪的 Y 轴

Strange Y-Axis on Flot Js

我正在使用 Flot Js 生成此图:

我的问题在 Y 轴上,它从 23:00:00 开始,也以 23:00:00 结束。我的目标是 Y 轴从 00:00:00 开始并在 23:59:59 结束。

我的js代码是:

$(function() {
    var data1 = [
    ["Pedro",gt(2015,05,13,20,01,00)],["João",gt(2015,05,13,07,09,00)],["José",gt(2015,05,13,00,00,00)],["Gustavo",gt(2015,05,13,13,00,00)],["Tenico Hotel",gt(2015,05,13,01,00,00)],["Gualter",gt(2015,05,13,23,25,00)],["Joao",gt(2015,05,13,02,30,00)],["José",gt(2015,05,13,00,00,00)],["Maria",gt(2015,05,13,00,00,00)],["Avatar",gt(2015,05,13,00,00,00)]     ];

    function gt(year, month, day,hours,min,secs){
        return new Date(year, month-1, day,hours,min, secs).getTime();
    }

    var chart = $("#chart");

    $.plot(chart, [data1],{
        series: {
            bars: {
                show: true,
                barWidth: 0.3,
                align: "center"
            }
        },
        xaxis: {
            mode: "categories",
            tickLength: 0
        },
        yaxis: {
            mode: "time",
            timeformat: "%H:%M:%S",
            min: (new Date("2015/05/13 00:00:00")).getTime(),
            max: (new Date("2015/05/13 23:59:59")).getTime(),
            tickSize: [1,"hour"]
        }
    });
    chart.resize();
});

已经搜索过,但没有找到任何线索。

提前致谢。

您 运行 遇到时区问题。

如果您将 'UTC' 添加到您的最小和最大日期字符串,您的 y 轴将从 00:00:00 变为 23:59:59。

我创建了一个 JS fiddle 来演示。您必须使用数据数组中的日期才能将它们也转换为 UTC。

Flot's API.md 详细说明了它如何处理日期:

Default behavior is that Flot always displays timestamps according to UTC. The reason being that the core Javascript Date object does not support other fixed time zones. Often your data is at another time zone, so it may take a little bit of tweaking to work around this limitation.

您还可以通过指定(来自 Flot API.md)来 set the timezone 轴:

yaxis: {
    mode: "time"
    timezone: null, "browser" or timezone (only makes sense for mode: "time")
}