Hi im trying to make a line chart for my web displaying data from my
database in MysQL but i get an Table has no colum and nothing display this
is my code.
I'm using as example the server side code from
https://developers.google.com/chart/interactive/docs/php_example
HTML
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript"
src="https://www.google.com/jsapi"></script>
<script type="text/javascript"
src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "getData.php",
dataType:"json",
async: false
}).responseText;
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);
// Instantiate and draw our chart, passing in some options.
var chart = new
google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, {width: 400, height: 240});
}
</script>
</head>
<body>
<!--Div that will hold the pie chart-->
<div id="chart_div"></div>
</body>
</html>
PHP
<?php
include_once 'Config.php'; //configuration of my Mysql Database
$public = 'admin'; //This variable is to select the user i want
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username,
$password);
$gsent = $conn->prepare("SELECT estado,Hora FROM Datos Where Usuario LIKE
'$public'");
$gsent->execute();
/* Obtener todas las filas restantes del conjunto de resultados */
$resultado = $gsent->fetchAll();
print json_encode($resultado );
}
catch (PDOException $pe) {
die("Could not connect to the database $dbname :" . $pe->getMessage());
}
?>
When i look at my print in getData.php i obtain this, the Mysql table only
has 3 row for admin with values:
Estado Hora
50 2015-02-16
53 2015-02-16
10 2015-02-16
[{"estado":"50","0":"50","Hora":"2015-02-16","1":"2015-02-16"},{"estado":"53","0":"53","Hora":"2015-02-16","1":"2015-02-16"},{"estado":"10","0":"10","Hora":"2015-02-16","1":"2015-02-16"}]
I know that the code display a pie chart, but because i'm a newbie with php
and i dont know anything of json or javascript first i want to make the
example like the one. How can i convert the result into a line chart?
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.