在 jQuery Flot 显示中使用日期
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3560960/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using dates in jQuery Flot display
提问by tchaymore
I'm trying to use Flot to plot a graph with dates. I've followed the advice on this string: herebut it doesn't seem to work for me. Here is my modified JavaScript (from that other question):
我正在尝试使用 Flot 绘制带有日期的图形。我遵循了关于这个字符串的建议:here但它似乎对我不起作用。这是我修改后的 JavaScript(来自另一个问题):
$(document).ready(function () {
var d1 = [[1262818800,100],[1262732400,100],[1262646000,100]];
var d2 = [[1262818800,23],[1262732400,23],[1262646000,23]];
$.plot($("#placeholder"), [{data:d1,lines:{show: true},label:"Mountain"},{data:d2,lines:{show: true},label:"Valley"}],{yaxis: {label:"cm"}},
{xaxis:
{mode:"time",
timeformat: "%M:%S"
}
});
});
I get a graph, but it doesn't convert the x-axis into dates, and the values on the x-axis don't even line up with what I've got in the data variables. I've even tried multiplying each datapoint by 1000 to convert to Javascript timestamps, but that didn't help either. I've also tried the following timeformat variables, in case that was the problem:
我得到了一个图表,但它没有将 x 轴转换为日期,并且 x 轴上的值甚至与我在数据变量中得到的值不一致。我什至尝试将每个数据点乘以 1000 以转换为 Javascript 时间戳,但这也无济于事。我还尝试了以下 timeformat 变量,以防出现问题:
"%M:%S", "%H:%S", "%y,%m,%d"
But no luck. Any ideas?
但没有运气。有任何想法吗?
回答by Impiastro
You should multiply to 1000 and use:
您应该乘以 1000 并使用:
xaxis: {
mode: "time"
}
I tested this way. I can post the full code if you need.
我是这样测试的。如果你需要,我可以发布完整的代码。
This is a little italian post about using flot to measure my baby's height and weight:
这是一篇关于使用 Flot 测量我宝宝的身高和体重的意大利小帖子:
The project code is downloadable from here.
项目代码可从此处下载。
Unzip it and open the file peso_giulia.html. Here you can find the d3 series.
解压并打开文件peso_giulia.html。在这里您可以找到 d3 系列。
You can replace the line
你可以更换线
,[(new Date("2009/12/29")).getTime(),67]
with the timestamp version
带有时间戳版本
,[(1282688250 * 1000), 100]