I try to make a google chart from a JSON file but i can't see the error. Here is my php that does the JSON data file. The php code works just fine it gives me this:
[["Durata pedeapsa","count"],["3","4"],["7","2"],["5","1"],["2","2"],["4","1"]]
However i cannot load it into the html.
<?php
//Oracle DB user name
$username = 'TW';
// Oracle DB user password
$password = 'TW';
// Oracle DB connection string
$connection_string = 'localhost/xe';
//Connect to an Oracle database
$connection = oci_connect(
$username,
$password,
$connection_string
);
$stid = oci_parse($connection, 'SELECT to_number(substr(durata_pedeapsa,0,1)) as "pedeapsa" , COUNT(DURATA_PEDEAPSA) as "count" FROM DETINUTI group by substr(durata_pedeapsa,0,1)');
if (!$stid) {
$e = oci_error($connection);
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$r = oci_execute($stid);
if (!$r) {
$e = oci_error($stid);
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
# set heading
$data[0] = array('Durata pedeapsa','count');
$i=1;
while (($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_LOBS)) != false) {
$pedeapsa = $row['pedeapsa'];
$count = $row['count'];
$data[$i] = array($pedeapsa,$count);
$i = $i +1;
}
echo json_encode($data);
oci_close($connection);
?>
And this is my html that should create the charts.
<html>
<head>
<title>Suji</title>
<!-- Load jQuery -->
<script language="javascript" type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js">
</script>
<script src="jquery.min.js"></script>
<script src="jquery-ui.min.js"></script>
<!-- Load Google JSAPI -->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "/test.php",
dataType: "json",
async: false
}).responseText;
var obj = window.JSON.stringify(jsonData);
var data = google.visualization.arrayToDataTable(obj);
var options = {title: 'Suji'};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;">
</div>
</body>
</html>