连接到数据库时显示Google Charts图表的问题

时间:2014-12-12 00:05:57

标签: php mysql google-visualization

我试图让Google Charts显示我在MySQL数据库中的图表。不幸的是,它没有显示任何内容。我知道我必须遇到某种小错误。

 <?php
        mysql_connect("Localhpst", "Username", "password");
         mysql_select_db("DBName") or die(mysql_error()); 


                 $sth=mysql_query("SELECT *
                FROM Graph")
             or die(mysql_error());

         $rows = array();
         $flag = true;
         $table = array();
         $table['cols'] = array(


             array('label' => 'people', 'type' => 'string'),
             array('label' => 'total', 'type' => 'number')
           );

        $rows = array();
            while($r = mysql_fetch_assoc($sth)) {
               $temp = array();
               $temp[] = array('v' => (string) $r['people']); 
               $temp[] = array('v' => (int) $r['total']);
               $rows[] = array('c' => $temp);
           }

      $table['rows'] = $rows;
      $jsonTable = json_encode($table);
  //echo $jsonTable;
 ?>

<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() {

        // Create our data table out of JSON data loaded from server.
         var data = new google.visualization.DataTable(<?=$jsonTable?>);
         var options = {
            title: ' Something ',
            is3D: 'true',
            width: 800,
            height: 600
        };

     var chart = new   google.visualization.PieChart(document.getElementById('chart_div'));
  chart.draw(data, options);
  }
 </script>
</head>

  <body>
     <!--this is the div that will hold the pie chart-->
       <div id="chart_div"></div>
       </body>
   </html>

缺少什么会导致屏幕上不显示任何内容。它唯一展示的是&#34; Something&#34;从标题。我知道数据库中有数据,所以不是问题。我也相当肯定它不是连接问题,所以我很难过。

0 个答案:

没有答案