9

有谁知道如何根据时间戳在浮点中显示日期

<script id="source" language="javascript" type="text/javascript">
$(function () {

var d1 = [
[1262818800,100],[1262732400,100],[1262646000,100],[1262559600,100],[1262473200,100],[1262386800,100],[1262300400,100],[1262214000,100],[1262127600,100],[1262041200,100],[1261954800,100],[1261868400,100],[1261782000,100],[1261695600,100],[1261609200,100],[1261522800,95],[1261436400,110],[1261350000,110],[1261263600,110],[1261177200,100];

var d2 = [
[1262818800,23],[1262732400,23],[1262646000,23],[1262559600,23],[1262473200,23],[1262386800,23],[1262300400,25],[1262214000,25],[1262127600,25],[1262041200,25],[1261954800,25],[1261868400,25],[1261782000,25],[1261695600,25],[1261609200,25],[1261522800,25],[1261436400,10],[1261350000,10],[1261263600,10],[1261177200,10]

$.plot($("#placeholder"), [{data:d1,lines:{show: true},label:"Mountain"},{data:d2,lines:{show: true},label:"Valley"}],{yaxis: {label:"cm"}},
{xaxis: {mode:"time"
}}
);

});
</script>
4

4 回答 4

22

我想您需要做的就是将时间戳(看起来像 unix 时间戳)乘以 1000。

Unix 时间戳将时间跟踪为从 1970 年 1 月 1 日开始的总秒数。而 javascript 时间戳以毫秒为单位。所以只需乘以 1000 就可以了

于 2010-01-07T17:45:07.307 回答
4

尝试定义 'timeformat' 属性,并定义 flot 用于格式化毫秒值的模式。

xaxis:{
    mode: "time",
    timeformat: "%M:%S"
},
于 2010-01-10T11:32:36.313 回答
2

我用这个:

    var options = {
    lines: { show: true },
    points: { show: true },
    xaxis: { mode: "time",  timeformat: "%m/%d/%y",   minTickSize: [1, "day"]}
};
于 2012-04-30T23:19:26.580 回答
0

我刚刚遇到了这个问题,我认为我们都使用了相同的错误 Flot 示例。签名是:

var plot = $.plot(placeholder, data, options)

你的代码正在做类似的事情

var plot = $.plot(placeholder, data, xoptions, yoptions)

所以要修复它,只需这样做:

$.plot(
    $("#placeholder"), 
    [{data:d1,lines:{show: true},label:"Mountain"},{data:d2,lines:{show:true},label:"Valley"}],
    {yaxis: {label:"cm"}, xaxis: {mode:"time"}}
);
于 2012-09-13T01:45:17.023 回答