flot点不符合日期和日期错误?

时间:2014-01-05 01:13:27

标签: php mysql flot

我的图表现在似乎到处都是..

我试图用从我的数据库收集的数据绘制一个flot图并且努力失败......

这是我的代码;

<?php   
//session_start();

//include('Includes/auth.php');
//require_once('header.php');
include('Includes/connect.php');

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf8"/>
<title>Index</title>
<script src="Includes/jquery-1.8.3.js"></script>
<script src="Includes/jquery.flot.js"></script>
<script src="Includes/jquery.flot.time.js"></script>

</head>
<?php
// Main query to pull data from 'tests' table
    $sql = "SELECT * FROM `tests` WHERE member_id = '1'";
    $result = mysql_query($sql) or die ("no query");

//  Dataset1
    while($row = mysql_fetch_assoc($result))
    {
    $dataset1[] = array ( strtotime( $row['date'] ) * 1000, sprintf( "%.3f", $row['test1'] ) );
    }
?>

<div id="chart1" style="width:600px;height:400px;"></div>

<script type="text/javascript">
    //Chart1
    var chart1Options = {
    xaxis: {
        mode: "time",
        timeformat: "%Y-%m-%d",
        axisLabel: 'Date' 
    },
      series: {
        lines: { show: true },
        color: "#fff",
        points: { show: true }
      },
       valueLabels: { show: true },
        grid: {
          backgroundColor: { colors: ["#4ca8fa", "#2887da"] },
          bordercolor: "#fff",
          borderwidth: "60",
          hoverable: true //IMPORTANT!
    }
    };

    var dataset1 = { label: "result", data: <?php echo json_encode($dataset1); ?>,};

    $.plot($("#chart1"), [ dataset1 ], chart1Options);
</script>
<?php echo json_encode($dataset1); ?>
</body>
</html>

这是我试图下拉并绘制

的数据

adata from mysql http://www.myreeftests.com/data.png

这是我使用上述细节的图表:

http://www.myreeftests.com/graphs2.php

xaxis上的所有地方和日期都错了?

请帮助。

由于

1 个答案:

答案 0 :(得分:0)

我注意到我的一个日期比另一个日期差了近2年,这使得数据丢失了。