You're not pulling "month" from the database, so when you try to access
$r['month'], you will get a null value. You need to add month to your SQL
query.
On Saturday, November 9, 2013 9:10:21 AM UTC-5, Nelson Idachi wrote:
>
> Hello..i have my charts running but i need my chart to show data per month.
> thats my sample code am using. Thank you
>
> <?php
>
> include ("connect.php");
>
> // write your SQL query here (you may use parameters from $_GET or $_POST
> if you need them)
> $query = mysql_query('SELECT problem, time, reccomend, rate1, rate2,
> improve FROM feedback');
>
> $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)
> */
> array('label' => 'month', 'type' => 'string'),
> array('label' => 'Problem', 'type' => 'number'),
> array('label' => 'time', 'type' => 'number'),
> array('label' => 'reccomend', 'type' => 'number'),
> array('label' => 'rate1', 'type' => 'number'),
> array('label' => 'rate2', 'type' => 'number'),
> array('label' => 'improve', 'type' => 'number'),
>
> // etc...
> );
>
> $rows = array();
> while($r = mysql_fetch_assoc($query)) {
> $temp = array();
> // each column needs to have data inserted via the $temp array
> $temp[] = array('v' => $r['month']);
> $temp[] = array('v' => $r['problem']);
> $temp[] = array('v' => $r['time']);
> $temp[] = array('v' => $r['reccomend']);
> $temp[] = array('v' => $r['rate1']);
> $temp[] = array('v' => $r['rate2']);
> $temp[] = array('v' => $r['improve']);
> // etc...
> // 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);
>
> // return the JSON data
> echo $jsonTable;
>
> ?>
> <!DOCTYPE html>
> <html>
> <head>
> <meta http-equiv="content-type" content="text/html; charset=UTF-8">
> <link rel="stylesheet" href="he.css" type="text/css"/>
> <title>My Chart</title>
> <script type='text/javascript' src="http://www.google.com/jsapi"></script>
> <script type='text/javascript'>
> //<![CDATA[
> function drawChart () {
> var data = new google.visualization.DataTable(<?php echo
> json_encode($table, JSON_NUMERIC_CHECK); ?>);
> var chart = new
> google.visualization.ColumnChart(document.querySelector('#chart_div'));
> chart.draw(data, {
> height: 500,
> width: 600
> });
> }
> google.load('visualization', '1', {packages:['corechart'], callback:
> drawChart});
> //]]>
> </script>
> </head>
> <body>
> <div id="chart_div"></div>
> </body>
> </html>
>
>
--
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/groups/opt_out.