0

我一直在尝试解决这个问题,但无法正确解决。我有以下 php 代码,它从 mysql 获取一些以毫秒为间隔存储的数据,并发送到客户端供 jqplot 绘制图形。

    <?php
    $unit = $_GET["units"];

    $sq="SELECT su_id FROM Station_stat
    WHERE su_id in ($unit) GROUP BY su_id";

    $res = mysql_query($sq);
    $first=true;
    echo "Label=";
    echo "[";
    while($row = mysql_fetch_array($res)){
        if ($first != true)
          echo ",";
          echo "{label:\"SUID ".$row['su_id']."\"}";
        $first = false;
      }
    echo "];";


    $sql="SELECT su_id FROM Station_stat
    WHERE su_id in ($unit) GROUP BY su_id";

    $result = mysql_query($sql);
    $first=true;
    echo "s1=";
    echo "[";
    while($row = mysql_fetch_array($result)){
    $suid = explode(",", $row['su_id']);

    if ($first != true)
    echo ",";
    $first = false;

    $count=count($suid);
    $i=0;
    while($i<$count)
      {
      getsuId($suid[$i]);
      ++$i;
      }
    }
    echo "];";

    function getsuId($suid){

    $start = $_GET["start"];
    $stop = $_GET["stop"];

    $qt=mysql_query("select TIMESTAMP(d_time), bs_rssi from Station_stat WHERE su_id ='".$suid."' and d_time BETWEEN '".$start."' and '".$stop."' GROUP BY d_time");

    $first=true;
    echo "[";
    while($row = mysql_fetch_array($qt)){
        if ($first != true)
          echo ",";
          echo "[\"".$row['TIMESTAMP(d_time)']."\",".$row['bs_rssi']."]";
          $first = false;
      }
    echo "]";
    }

    mysql_close();
    ?>

下面是通过单击按钮向 php 脚本发送和接收数据的函数。

    function display() {
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    } else {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
    eval(xmlhttp.responseText);
    drawPlot();
      }
    }
    var units = document.getElementById('suid').value;
    var stat = document.getElementById('start').value;
    var stop = document.getElementById('stop').value;
    var query = "?units=" + units ;
      query +=  "&start=" + start ;
      query +=  "&stop=" + stop;
    xmlhttp.open("GET","../chart.php" + query , true);
    xmlhttp.send();
    }

    function drawPlot() {
    var start = $("#start").val();
    plot1 = $.jqplot("chart1", s1, {
    //title: "Aera Chart",
    series: Label, 
    axes: { 
        xaxis: { 
             renderer:$.jqplot.DateAxisRenderer, 
             min: start,
             tickInterval: '2 minute',
             tickRenderer: $.jqplot.CanvasAxisTickRenderer,
             tickOptions: {
                    formatString: '%Y-%m-%d %H:%M:%S',
                    angle: -55
                    }
             },
        yaxis: {
             label: "[RSSI] ",
             tickOptions:{formatString:'%d '}
        }

        }, 
     cursor:{
              show: true, 
              zoom: true
     },
     legend: { show: true }
     });
     plot1.redraw();
     }

我现在遇到的问题是:

(1) 渲染图形需要时间(如 20-30 秒)。

(2) 每当我拖动缩放时,页面就不会响应。

请感谢您的帮助。谢谢你。

4

1 回答 1

0

在这个项目休息了几天后,我终于意识到我在粘贴的 Ajax 函数代码中犯了一个错误。我将要发送到服务器端的参数之一声明为“stat”,但是在将其添加到其他参数时,我添加了“start”。

    var stat = document.getElementById('start').value;
    query +=  "&start=" + start ;

编辑该行后,我可以看到 jqplot 对加载图的响应速度更快。谢谢你。

于 2012-10-18T15:58:12.957 回答