2015-11-30 180 views
1

所以,我做了一個網頁,有很多來自Pingdom的數據。 頁面本身包含幾個谷歌折線圖和這些工作完全當我只顯示單個checkid信息。添加多行到谷歌折線圖

但是當我試圖添加多行(爲了能夠在一個圖表中顯示幾個checkids)它只是不工作,因爲它應該。

該行正在制定,但它們不是畫在彼此的頂部! :(

下面是我的代碼,試圖添加幾行到折線圖 請注意,從數據庫中獲取信息的php文件,通過$ _GET變量執行此操作(稍後您會看到在JavaScript代碼中,爲什麼我試圖將所有數據集合到一個數據集中)

注意: 目前,下面的代碼部分需要大量額外的工作,所以不要指出安全缺陷我只是需要圖表才能工作,然後再繼續修復安全問題。

PHP:

<?php 
$dt = new DateTime(); 
$dt->setTimeZone(new DateTimeZone('Europe/Oslo')); 

$con=mysqli_connect("127.0.0.1","root","","PingdomStats"); 
$checkId = $_GET['checkId']; 


// first we need to list out all the internal checks 
$sql = "SELECT CheckId, CheckName, Category FROM Checks WHERE CheckId=$checkId "; 
$checkList = mysqli_query($con,$sql); 

$checkListCopy = $checkList; 
$sqlResponseTimes = ""; 

$rows = array(); 
$table = array(); 

$table['cols'] = 
array 
(
    array('label' => 'Check name', 'type' => 'string'), 
    array('label' => 'Response time', 'type' => 'number') 
); 


if(mysqli_num_rows($checkList) > 0) 
{ 

    while($row = mysqli_fetch_row($checkList)) 
    { 
    $sqlResponseTimes = " SELECT 
          FROM_UNIXTIME(Resp.checkTime, '%Y-%m-%d %h:%i:%s') AS CheckTime, 
          Resp.ResponseTime AS '$row[1]' 
          FROM ResponseTimes AS Resp 
          WHERE 
          Resp.Checkid = $row[0] 
          ORDER BY Resp.Id DESC LIMIT 10 "; 




    //do a new query based on the sql query we just created. 

    $responseTimeList = mysqli_query($con,$sqlResponseTimes); 

    while($rowInner = mysqli_fetch_array($responseTimeList,MYSQLI_ASSOC)) 
    { 
     $temp = array(); 
     $temp[] = array('v' => (string)$row[1]." ".$rowInner['CheckTime']); 
     $temp[] = array('v' => (int) $rowInner[$row[1]]); 

     $rows[] = array('c' => $temp); 
    } 
} 

$table['rows'] = $rows; 

echo json_encode($table); 
} 

這裏是JS代碼:

var jsonData0 = 
$.ajax(
{ 
    url: "important_test.php?checkId=1575894", 
    dataType:"json", 
    async: false 
}).responseText; 

var data0 = new google.visualization.DataTable(jsonData0); 

var jsonData1 = 
$.ajax(
{ 
    url: "important_test.php?checkId=1653903", 
    dataType:"json", 
    async: false 
}).responseText; 

var data1 = new google.visualization.DataTable(jsonData1); 

var jsonData2 = 
$.ajax(
{ 
    url: "important_test.php?checkId=1575824", 
    dataType:"json", 
    async: false 
}).responseText; 

var data2 = new google.visualization.DataTable(jsonData2); 

var jsonData3 = 
$.ajax(
{ 
    url: "important_test.php?checkId=1579531", 
    dataType:"json", 
    async: false 
}).responseText; 

var data3 = new google.visualization.DataTable(jsonData3); 

var jsonData4 = 
$.ajax(
{ 
    url: "important_test.php?checkId=1645709", 
    dataType:"json", 
    async: false 
}).responseText; 

var data4 = new google.visualization.DataTable(jsonData4); 

var options = 
{ 
    curveType: 'function', 
    is3D: true, 
    width: document.getElementById('internalLineGraph').clientWidth, 
    height: 400, 

}; 

var join_data0_Data1 = new google.visualization.data.join(data0,data1,'full',[[0,0]],[1],[1]); 

var join_data2_Data3 = new google.visualization.data.join(data2,data3,'full',[[0,0]],[1],[1]); 

var data0_to_data3 = new google.visualization.data.join(data0_Data1,data2_Data3,'full',[[0,0]],[1,2],[1,2]); 

var chart = new google.visualization.LineChart(document.getElementById('internalLineGraph')); 

chart.draw(data0_to_data3, options); 

見附圖: Graph showing info from internal Pingdom database

+0

沒關係我的問題,我在今天的運動會議期間自己解決了它。 :] 我忘了在JSON表添加一個公共ID) –

回答

0

我忘了補充一個共同的ID,以便能夠加入JSON表。 現在它的工作原理應該如此!