在jQuery Flot显示中使用日期 [英] Using dates in jQuery Flot display

查看:487
本文介绍了在jQuery Flot显示中使用日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Flot绘制带有日期的图形。我遵循了这个字符串的建议:这里但这似乎不适合我。这是我修改的JavaScript(从另一个问题):

I'm trying to use Flot to plot a graph with dates. I've followed the advice on this string: here but it doesn't seem to work for me. Here is my modified JavaScript (from that other question):

$(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"
 }
    });

});

我得到一个图形,但它不会将x轴转换为日期,值在x轴上甚至不能与数据变量中的数据一致。我甚至尝试将每个数据点乘以1000,以转换为Javascript时间戳,但这也没有帮助。我也尝试过以下时间格式的变量,以防出现问题:

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:

"%M:%S", "%H:%S", "%y,%m,%d"

但没有运气。任何想法?

But no luck. Any ideas?

推荐答案

您应该乘以1000,并使用:

You should multiply to 1000 and use:

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:

  • http://www.bits4beats.it/sviluppo-web/controllare-il-peso-del-bimbo-tramite-html-e-jquery/

项目代码可以从这里

解压缩并打开文件

peso_giulia.html 。在这里,您可以找到d3系列。

Unzip it and open the file peso_giulia.html . Here you can find the d3 series.

您可以替换行

,[(new Date("2009/12/29")).getTime(),67]

与时间戳版本

,[(1282688250 * 1000), 100]

这篇关于在jQuery Flot显示中使用日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆