I am trying to create a line chart for displaying time vs products sold. The MySQL statement is tested fine and brings back the data I want from the two specific columns timecol and regular.
I have attached the two files. If anyone can tell me why these are not working I would really appreciate it as I cant seem to find any decent example of MySQL into line charts. (OBVIOUSLY THE CONNECTION DETAILS HAVE BEEN REMOVED) Index.php <html> <head> <script type="text/javascript" src="https://www.google.com/jsapi"></script > <script type="text/javascript" src=" http://ajax.googleapis.com/ajax/libs/jquery/1.8.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 json = $.ajax({ url: 'get_json.php', // make this url point to the data file dataType: 'json', async: false }).responseText; // Create our data table out of JSON data loaded from server. var data = new google.visualization.DataTable(json); var options = { title: 'Daily Sales', is3D: 'true', width: 800, height: 600 }; // Instantiate and draw our chart, passing in some options. //do not forget to check ur div ID 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> get_json.php <?php $con = mysql_connect('**********', '***********', '**********') or die('Error connecting to server'); mysql_select_db("*********", $con); // write your SQL query here (you may use parameters from $_GET or $_POST if you need them) $query = mysql_query("SELECT timecol, regular FROM SalesData WHERE site='marketstreet' AND datecol='28062015' AND regular>=1 GROUP BY timecol"); $table = array(); $table['cols'] = array( /* define your DataTable columns here * each column gets its own array * syntax of the arrays is: * label => column label * type => data type of column (string, number, date, datetime, boolean) */ // I assumed your first column is a "string" type // and your second column is a "number" type // but you can change them if they are not array('label' => 'timecol', 'type' => 'string'), array('label' => 'regular', 'type' => 'string') ); $rows = array(); while($r = mysql_fetch_assoc($query)) { $temp = array(); // each column needs to have data inserted via the $temp array $temp[] = array('v' => (int) $r['timecol']); $temp[] = array('v' => (int) $r['regular']); // typecast all numbers to the appropriate type (int or float) as needed - otherwise they are input as strings // insert the temp array into $rows $rows[] = array('c' => $temp); } // populate the table with rows of data $table['rows'] = $rows; // encode the table as JSON $jsonTable = json_encode($table); // set up header; first two prevent IE from caching queries header('Cache-Control: no-cache, must-revalidate'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Content-type: application/json'); // return the JSON data echo $jsonTable; ?> My long term goal is to show the data as time series but just to get a line chart working would be a good start. Thanks in advance. -- 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.
