2013-07-03 23 views
0

我一直在這一段時間,試圖讓highcharts以圖表的PHP返回一些數據。我做了很多搜索,沒有任何工作。我可以寫PHP來傳遞數據,但它需要但你如何得到它動態圖表?Highcharts和PHP的動態圖表

我可以將其作爲: [[ 「1372875867」, 「44.8782806」],[ 「1372875885」, 「46.2020226」]] 或 [[1372876686,44.0655823],[1372876693,43.3360596]等]

,但我如何才能從PHP輸出到它們顯示dyname示例中的數據?????

!DOCTYPE HTML> 
    <html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <title>Highstock Example</title> 

    <script type="text/javascript" 
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
    <script type="text/javascript"> 
    $(function() { 

Highcharts.setOptions({ 
    global : { 
     useUTC : false 
    } 
}); 

// Create the chart 
window.chart = new Highcharts.StockChart({ 
    chart : { 
     renderTo : 'container', 
     events : { 
      load : function() { 

       // set up the updating of the chart eachsecond 
       var series = this.series[0]; 
       setInterval(function() { 
        var x = (new Date()).getTime(), 
        y = Math.round(Math.random() * 100); 
        series.addPoint([x, y], true, true); 
       }, 1000); 
      } 
     } 
    }, 

    rangeSelector: { 
     buttons: [{ 
      count: 1, 
      type: 'minute', 
      text: '1M' 
     }, { 
      count: 5, 
      type: 'minute', 
      text: '5M' 
     }, { 
      type: 'all', 
      text: 'All' 
     }], 
     inputEnabled: false, 
     selected: 0 
    }, 

    title : { 
     text : 'Live random data' 
    }, 

    exporting: { 
     enabled: false 
    }, 

    series : [{ 
     name : 'Random data', 
     data : (function() { 
      // generate an array of random data 
      var data = [], time = (new Date()).getTime(), i; 

      for(i = -999; i <= 0; i++) { 
       data.push([ 
        time + i * 1000, 
        Math.round(Math.random() * 100) 
       ]); 
      } 
      return data; 
     })() 
    }] 
     }); 

    }); 

    </script> 
</head> 
<body> 
    <script src="../../js/highstock.js"></script> 
    <script src="../../js/modules/exporting.js"></script> 

    <div id="container" style="height: 500px; min-width: 500px"></div> 
</body> 
    </html> 

我目前的PHP是:

<?php 
    // include("$_SERVER[DOCUMENT_ROOT]/config/config.php"); 
    include("adodb5/adodb.inc.php"); 
    $connection = new COM("ADODB.Connection") or die("Cannot start ADO"); 
    $result_set = $connection->Execute(" 
      SELECT tag, TIME, value 
      FROM picomp 
      WHERE TIME >= '*-3m' AND tag = 'xxx:xx_xxx.xxx' 
      "); 

    $result_count = 0; 
    // $labels = array(); 
    while (!$result_set->EOF) { 
$pidate = date("U", strtotime($result_set->fields[1])); 
if ($result_count <> 0){ 
print ","; 
}else{ 
print "["; 
} 
    print "[".$pidate.",".$result_set->fields[2]."]"; 
    //  array_push("{$result_set->fields[2]}"); 
    $result_count = $result_count +1; 
    $result_set->MoveNext(); 
    // echo "testing"; 
    } 
    print "];"; 

回答

0

您可以使用HighchartsPHP這是Highcharts的包裝,它基本上可以讓你用PHP編寫所有的JS代碼。這是非常有用和非常簡單的使用。

HighchartsPHP on GitHub

+0

我知道這可以做到沒有highchartsphp我希望有人可以告訴我如何修改他們的例子調用PHP程序,它的數據傳遞給它。 – klmbear

0

你的時間戳也應乘以1000,並且這兩個值應該是數字。

請詳細說明,如何準備JSON,因爲您只打印「如JSON」,但事實並非如此。

採取看看http://php.net/manual/en/function.json-encode.php,其中介紹了一些例子。

+0

問題是我如何將php與頂部的html綁定? – klmbear

+0

看看http://docs.highcharts.com/#preprocessing-data-from-a-database示例 –