Graphic in google charts php mysql not working -
i having problems output of graphic. graphic appears empty. want construct graphic shows number of users registered in year/month.
the values getting database are:
example: id=1 , registado = 2014-05-04 id=2 , registado = 2014-07-09
the code divide in 2 files 1 fields database , functions call graphic , query put data in graphic.
the output query:
1 may 20148 jul 201411 aug 2014
the respective code:
getpiechartdata.php
<?php $dbuser="root"; $dbname="dissertacao"; $dbpass=""; $dbserver="localhost"; $sql_query = "select id,registado,monthname(registado), year(registado), sum(id) utilizadores group year(registado), month(registado)"; $con = mysql_connect($dbserver,$dbuser,$dbpass); if (!$con){ die('could not connect: ' . mysql_error()); } mysql_select_db($dbname, $con); $result = mysql_query($sql_query); $total_rows = mysql_num_rows($result); $row_num = 0; while($row = mysql_fetch_array($result)){ $dados .= "['".$row{'id'}."',"(' m y', strtotime($row['registado']),"; } mysql_close($con); ?>
index.php
<html> <head> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("visualization", "1.1", {packages:["bar"]}); function drawitems(num) { var jsonpiechartdata = $.ajax({ url: "getpiechartdata.php", data: "q="+num, datatype:"json", async: false }).responsetext; google.setonloadcallback(drawchart); function drawchart() { var data = google.visualization.arraytodatatable([ ['numero de utilizadores', 'data'], <?php echo $dados ?> ]); var options = { title: 'numero de utilizadores registados', curvetype: 'function', legend: { position: 'bottom' } }; var chart = new google.visualization.linechart(document.getelementbyid('chart_div')); chart.draw(data, options); } </script> </head> <body> <div id="chart_div"></div> </body> </html>
Comments
Post a Comment