发车日期问题

发布于 2024-11-17 17:32:04 字数 1050 浏览 3 评论 0原文

我正在尝试在 flot 中显示日期字段:

数据:

    var data = [
            [parseInt(1309150800.0)*1000, 220],
            [parseInt(1309064400.0)*1000, 230],
    ];

Flot 创建:

    $.plot($("#graph"), [ data ], {
        grid: {
            hoverable: true
        },
        xaxis: {
            mode: "time",
            timeformat: "%d.%m.%y"
        },
        yaxis: {
            mode: "number",
            tickSize: 2
        },
        series: {
            lines: { show: true },
            points: { show: true }
        }
    });

根据此站点 http://tools.semsym.com/index.php?tool=timestamp&timestamp=1309150800 时间戳是 Jun 2011 年 26 日晚上 10:00:00。 但图表看起来像: https://i.sstatic.net/NUayx.png

点有点不对劲。第一个应该是 26,但现在是 25.5。我玩了一下时间戳格式,但无法将其达到特定点。

我缺少什么?

它还显示“26.06.2011”大约 6 次。需要什么配置才能将其保持为 1?

i'm trying to display a date field in flot:

Data:

    var data = [
            [parseInt(1309150800.0)*1000, 220],
            [parseInt(1309064400.0)*1000, 230],
    ];

Flot creation:

    $.plot($("#graph"), [ data ], {
        grid: {
            hoverable: true
        },
        xaxis: {
            mode: "time",
            timeformat: "%d.%m.%y"
        },
        yaxis: {
            mode: "number",
            tickSize: 2
        },
        series: {
            lines: { show: true },
            points: { show: true }
        }
    });

According to this site http://tools.semsym.com/index.php?tool=timestamp×tamp=1309150800 the timestamp is Jun 26, 2011 10:00:00 PM.
But the graph looks like: https://i.sstatic.net/NUayx.png

The dots are a bit off. The first one should be at 26, but is at 25,5. I played a bit with timestamp formatting but wasn't able to get it to the specific point.

What am i missing?

Also it shows "26.06.2011" about 6 times. What config is needed to keep it at 1?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪是无色的血 2024-11-24 17:32:04

确保设置了 minTickSize。这是 http://jsfiddle.net/hAXHq/ 的示例,其中我将 minTickSize 设置为 1 天,明确设置最小/最大值。您应该能够根据您的数据以编程方式设置自己的最小值/最大值。

这是代码:

    var data =  [
        [parseInt(1309150800.0)*1000, 220],
        [parseInt(1309064400.0)*1000, 230]
    ];

    $.plot($("#placeholder"), [ data ], {
    grid: {
        hoverable: true
    },
    xaxis: {
        mode: "time",
        timeformat: "%d.%m.%y",
            minTickSize: [1,"day"],
        min: (new Date(2011,5,25)).getTime(),
        max: (new Date(2011, 5, 28)).getTime()
    },
    yaxis: {
        mode: "number",
        tickSize: 2
    },
    series: {
        lines: { show: true },
        points: { show: true }
    }
});

Make sure you set a minTickSize. Here is an example at http://jsfiddle.net/hAXHq/ where I have set minTickSize to 1 day and set the min/max values explicitly. You should be able to set your own min/max programmatically depending on your data.

Here is the code:

    var data =  [
        [parseInt(1309150800.0)*1000, 220],
        [parseInt(1309064400.0)*1000, 230]
    ];

    $.plot($("#placeholder"), [ data ], {
    grid: {
        hoverable: true
    },
    xaxis: {
        mode: "time",
        timeformat: "%d.%m.%y",
            minTickSize: [1,"day"],
        min: (new Date(2011,5,25)).getTime(),
        max: (new Date(2011, 5, 28)).getTime()
    },
    yaxis: {
        mode: "number",
        tickSize: 2
    },
    series: {
        lines: { show: true },
        points: { show: true }
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文