[英]Google charts are not displaying with new release
這是我在新版本的Google Api之前用於柱狀圖的我的代碼,它工作正常。 現在我的圖表沒有顯示。 我已經檢查了新版本的更改,但發現相關。 第一個問題出現在數組中的數據類型上,float數據類型不合法,如果我將其替換為其他某種數據類型,則圖表仍不會顯示。 如果我將浮點數更改為字符串,則將出現錯誤,即不會在X軸上使用字符串數據類型。 我在X軸上繪制了時間,在Y軸上繪制了距離。 如果有人知道如何根據新版本的Google Api更改代碼,請分享您的代碼或一些信息。
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="mysql"; // Database name
$tbl_name="gprs"; // Table name
// Connect to server and select database.
$con=mysql_connect("$host", "$username")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$data = mysql_query("select SUM(Distance) as Distance, CAST( Time AS date) as Time from gprs where DeviceId=25 and Time between '2013-08-08' and '2013-09-31' group by CAST(Time AS date) order by CAST( Time AS date)")
or die(mysql_error());
$table = array();
$table['cols'] = array(
array('label' => 'TIME', 'type' => 'string'),
array('label' => 'Distance', 'type' => 'float')
);
$rows = array();
while ($nt = mysql_fetch_assoc($data))
{
$temp = array();
$temp[] = array('v' => (string)$nt['TIME']);
$temp[] = array('v' =>(float) $nt['Distance']);
$rows[]['c'] = $temp;
}
$table['rows'] = $rows;
$jsonTable = json_encode($table);
?>
<!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">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>
Google Visualization API Sample
</title>
<script type="text/javascript" src="//www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1', {packages: ['corechart']});
</script>
<script type="text/javascript">
function drawVisualization() {
// Create and populate the data table.
var data = new google.visualization.DataTable(<?=$jsonTable?>);
// Create and draw the visualization.
new google.visualization.ColumnChart(document.getElementById('visualization')).
draw(data);
}
google.setOnLoadCallback(drawVisualization);
</script>
</head>
<body style="font-family: Arial;border: 0 none;">
<div id="visualization" style="width: 600px; height: 300px;"></div>
</body>
</html>
我已經解決了上述問題。 用此array('label'=>'TIME','type'=>'string'),array('label'=>'fuel','type'=>'number')替換上面的數組
和這個$ temp [] = array('v'=> $ nt ['TIME']); $ temp [] = array('v'=> $ nt ['fuel']);
並且不要使用Packages:columnchart現在在新的Api版本中將其替換為corechart
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.