Jump to content

Google Pie Chart


honkmaster

Recommended Posts

Hi I'm using a the following google Pie Cart from here http://code.google.com/apis/ajax/playground/#pie_chart

 

I would like to use php to COUNT printers listed in a column called machine and return result so I can echo it into google code

 

Example of Column below would return a count of one for each except for the TurboJet which would return two.

 

I would then like to echo the results to the google Javascript for printer 1 to 6.

_______

machine

________

FB7500-1

TurboJet

XL1500-1

Roland

Canon

TurboJet

 

Can anyone help?

 

Cheers Chris

 

<?php
mysql_connect("localhost","chris","Cr2baxKUHWGxr6nn");
@mysql_select_db("schedule") or die( "Unable to select database");

date_default_timezone_set('Europe/London');

$query = "SELECT machine, COUNT(machine) FROM maindata GROUP BY machine"; 

$result = mysql_query($query) or die(mysql_error());

// Print out result
while($row = mysql_fetch_array($result)){
echo "There are is ". $row['COUNT(machine)'] ." ". $row['machine'] ." items.";
echo "<br />";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>
      Google Visualization API Sample
    </title>
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load('visualization', '1', {packages: ['corechart']});
    </script>
    <script type="text/javascript">
      function drawVisualization() {
        // Create and populate the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Task');
        data.addColumn('number', 'Hours per Day');
        data.addRows(5);
        data.setValue(0, 0, 'Printer 1');
        data.setValue(0, 1, 11);
        data.setValue(1, 0, 'Printer 2');
        data.setValue(1, 1, 2);
        data.setValue(2, 0, 'Printer 4');
        data.setValue(2, 1, 2);
        data.setValue(3, 0, 'Printer 5');
        data.setValue(3, 1, 2);
        data.setValue(4, 0, 'Printer 6');
        data.setValue(4, 1, 7);
      
        // Create and draw the visualization.
        new google.visualization.PieChart(document.getElementById('visualization')).
            draw(data, {title:"Current Work in Progress"});
      }
      

      google.setOnLoadCallback(drawVisualization);
    </script>
  </head>
  <body style="font-family: Arial;border: 0 none;">
    <div id="visualization" style="width: 600px; height: 400px;"></div>
  </body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.