Try this:
$data = array(array('Server, Month, Year', 'Number of Toner Cartridges
Used'));
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row[0] . "</td>";
echo "<td>" . $row[1] . "</td>";
echo "</tr>";
$data[] = array($row[0], $row[1]);
}
Then, in javascript:
function drawChart () {
var data = google.visualization.arrayToDataTable(<?php echo
json_encode($data, JSON_NUMERIC_CHECK); ?>);
// draw a ColumnChart
// you can change this to whatever chart type you need
var chart = new
google.visualization.ColumnChart(document.querySelector('#myChart'));
chart.draw(data, {
// chart options, eg:
height: 400,
width: 600
});
}
google.load('visualization', '1', {packages: ['corechart'], callback:
drawChart});
and then in HTML, below your table:
<div id="myChart"></div>
You can change the id of the div, just make sure to change it in the
chart's constructor as well.
On Monday, July 7, 2014 2:12:25 PM UTC-4, khalil negron wrote:
>
> Trying to turn this data retrieved from mysql database into a chart or
> graph.
> Here my code queries the database and displays it as a table, i want to
> also display it as a chart underneath the table. I have read all the google
> doc information still can not grasp this. Can someone help.
>
> Thanks
>
> <?php
>
> //formula for toner usage total pages/35000 = #toner used for month
>
> if(isset($_POST["YEAR"])) {
> $year = $_POST['YEAR'];
> $result = mysqli_query($dbhandle,"SELECT `Servers`, `Total Pages` /
> 35000 FROM summaryofserver WHERE
> RIGHT(Servers,4) = '$year'");
> $result2 = mysqli_query($dbhandle, "SELECT SUM(`Total Pages` / 35000) FROM
> summaryofserver WHERE
> RIGHT(Servers,4) = '$year'");
> echo "<table border='1'>
> <tr>
> <th>Server, Month, Year</th>
> <th>Number of Toner Cartridges Used</th>
> </tr>";
> while($row = mysqli_fetch_array($result)) {
> echo "<tr>";
> echo "<td>" . $row[0] . "</td>";
> echo "<td>" . $row[1] . "</td>";
> echo "</tr>";
> }
> $sum = mysqli_fetch_array($result2);
> echo "<tr>";
> echo "<td>" .'Total for Year:'. $year. "</td>";
> echo "<td>" . $sum[0] . "</td>";
> echo "</tr>";
> echo "</table>";
> }
> ?>
>
--
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.