Hi I have a basic Pie Chart that, upon running the PHP script and viewing the page source in the browser shows that the data is retrieved correctly using mysql_fetch_array()
however, no pie chart is displayed in the browser. here is the php script
<!DOCTYPE html>
<?php
include("config.php");
$my_db = "asmf";
$link = mysqli_connect($dbhost, $dbuname, $dbpass, $my_db);
$q = "select * from $my_db.expenses GROUP BY exp_type";
$r = mysqli_query($link, $q);
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
?>
<html>
<head>
<title>ASMF-eTrucker Expense Pie Chart</title>
<script type="text/javascript" src="
https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load("current", {packages:["corechart"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Expense Type', 'Amount'],
<?php
while($row = mysqli_fetch_array($r)) {
//echo $row["amount"]."<br>";
echo "['".$row['exp_type']."', '".$row['amount']."'],";
}
?>
]);
var options = {
title: 'Percent of Expense Types'
};
var chart = new google.visualization.PieChart(document.getElementById('piechart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div style="width:900px;">
<h3>ASMF-eTrucker Expense Pie Chart</h3>
<br />
<div id="piechart" style="width: 900px; height: 500px;"></div>
</div>
Where could the code be failing?
Gregg