0

我正在从 MySQL 数据库中提取数据并使用 Flot 进行绘图。我的问题出在我们的数据库设计中。
我有 1 个包含以下列的表:

  1. ID(自动递增)(键)
  2. 时间戳
  3. SensorData(看起来像:34534.3 32452.4 23454.6 6523.45 67546.4 2233)

我想解析我的传感器数据,以便可以使用单个传感器数据创建 Flot 图。现在,我能够绘制 ID vs Timestamp 并且有效。这是我的代码:

    <html>
 <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Flot Examples</title>
    <link href="layout.css" rel="stylesheet" type="text/css">
    <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="js/flot/excanvas.min.js"></script><![endif]-->
    <script language="javascript" type="text/javascript" src="js/flot/jquery.js"></script>
    <script language="javascript" type="text/javascript" src="js/flot/jquery.flot.js"></script>
 </head>
    <body>
    <h1>Title</h1>

    <div id="placeholder" style="width:600px;height:300px;"></div>

<?php

    $server = "www.freesql.org";
    $user="username";
    $password="password";
    $database = "database";

    $connection = mysql_connect($server,$user,$password);
    $db = mysql_select_db($database,$connection);

    $query = "SELECT Id, localtme FROM varia";
    $result = mysql_query($query);

    while($row = mysql_fetch_assoc($result))
    {
        $dataset1[] = array($row['Id'],$row['localtme']);
    }
?>


<script type="text/javascript">
$(function () {
    var dataset1 = <?php echo json_encode($dataset1); ?>;

    $.plot($("#placeholder"), [ dataset1 ]);
});
</script>
 </body>
</html>
4

0 回答 0