绘制图表x轴时间问题... AARGHHH [英] Flot charts x-axis time issues... AARGHHH

查看:101
本文介绍了绘制图表x轴时间问题... AARGHHH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难将数据显示在Flot图表中,x轴作为时间轴。这是我的JSON文件的缩写副本:

I am having a difficult time getting my data to display inside of a Flot chart with the x-axis serving as the timeline. Here is an abbreviated copy of my JSON file:

{
  "label": "ServiceReport",
  "data": [[1328983200, 53], [1328986800, 53], [1328990400, 60]]
}

我已经按照Flot API页面上的教程,以及这个一个在stackoverflow上

I've followed the tutorials on the Flot API page, as well as this one on stackoverflow

没有任何运气。

修改x轴时,这会让图表显示得很好,但x轴是空白的。

When modifying the x-axis, this gets the graph to display just fine, but the x-axis is blank.

xaxis: { mode: "time", minTickSize: [1, "hour"]}

这显示8到8个值(根据数据文件不正确),但没有图表数据:

This displays 8 through 8 values (not correct according to data file), but no graph data:

xaxis: { mode: "time", minTickSize: [1, "hour"],
                min: (new Date("2000/01/01")).getTime(),
                max: (new Date("2000/01/02")).getTime()

            }

基本上,我只是想在x轴上显示小时(实际上是任何格式:5:00,5 AM,无关紧要),并且y轴与之相关服务价值观。每个数据文件中有24个总时间戳(一天的数据值)。

Basically, I just want to display the hours in (really any format: 5:00, 5 AM, doesn't matter) on the x-axis, and have the y-axis correlate to the Service Values. There are 24 total timestamps in each data file (one day's worth of data).

您的任何帮助Flot和JavaScript / jQuery专家将不胜感激!!! / p>

Any help from you Flot and JavaScript/jQuery experts would be greatly appreciated!!!

推荐答案

首先要显示时间,请使用:

First for the time to display, use :

 xaxis: { mode: "time",minTickSize: [1, "hour"],timeformat: "%H:%I:%S"}

由于错误的JSON编码文件导致JSON数据出现同样的问题。
你确定你的JSON文件真的是一个JSON文件吗?
让我们尝试一下ike来测试它(例如用jquery):

I had the same problems with JSON data, caused by a bad JSON encoding file. Are you sure that your JSON file is really a JSON file ? Let's try something ike that to test it (with jquery for example) :

$.getJSON('yourJSONpage.php', 
    function(data) {
        testData=data.pop();
        alert(testData[0]);
});

最后一点,你的时间戳不正确,正确的时间戳就像是1328983200000不是那样的1328983200,如果您使用PHP生成JSON数据,请确保您为日期执行类似的操作:

Last point, your timestamp is not correct, correct time stamp is like that "1328983200000" not like that "1328983200", if you use PHP to generate your JSON data, make sure you do something like that for the dates :

$hour=mktime($h+1,$i,$s,$m,$d,$y)*1000;

这篇关于绘制图表x轴时间问题... AARGHHH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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