1

我创建了一个页面,它从表格中获取数据view_name并使用谷歌图形 API 显示图表。当我在本地主机上运行系统时,它会给出正确的结果并显示图表。

当我在我的 ec2 linux 实例上创建相同的数据库并获取相同的文件时,其他一切正常,只是图表没有出现。我检查了firebug结果,它表明json string在 ec2 实例上 json 字符串为假时进入 localhost 获取了正确的数据。

我在本地主机上运行时的 json 字符串: {"cols":[{"label":"pcount","type":"string"},{"label":"ncount","type":"number"}],"rows":[{"c":[{"v":"pcount"},{"v":179}]},{"c":[{"v":"ncount"},{"v":237}]}]}

我在 ec2 实例上运行时的 json 字符串: {"cols":[{"label":"pcount","type":"string"},{"label":"ncount","type":"number"}],"rows":[{"c":[{"v":""},{"v":0}]},{"c":[{"v":""},{"v":0}]},{"c":[{"v":""},{"v":0}]},{"c":[{"v":""},{"v":0}]},{"c":[{"v":""},{"v":0}]}]}

我的桌子是:

+----------+-----------+
| ind_type | Index_val |
+----------+-----------+
| pcount   |       179 |
| ncount   |       237 |          which is same on localhost and ec2 instance.
+----------+-----------+

我的 php 页面 url.php 包含 GUI 按钮:

<html>
   <head>
      <title>ThenWat</title>

    <meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
    <meta content="utf-8" http-equiv="encoding" />
     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>   
     <script type="text/javascript" src="https://www.google.com/jsapi"></script>
     <script type="text/javascript">
    google.load('visualization', '1', {'packages':['corechart']});
    google.setOnLoadCallback(drawChart);    


    function drawVisualization(dataFromAjax) {

    var jsonData = $.ajax({
          url: "ajax_graph_temp.php",
          dataType:"json",
          async: false
          }).responseText;
    var data = new google.visualization.DataTable(jsonData);
        var options = {
           title: 'Index analysis',
          is3D: 'true',
          width: 800,
          height: 600
        };
        var chart = new google.visualization.PieChart(document.getElementById('txtHint'));
        chart.draw(data, options);
         }
function makeAjaxCall() {
      $.ajax({url:'url.php',
              data: {},
              success: function(responseData) {
                         drawVisualization();
                       }
        });
    }
     </script>
   </head>
   <body style="height: 560px">
         <div style="z-index: 1; left: 660px; top: 160px; position: absolute; margin-top: 0px"> 
            <button onclick="makeAjaxCall(); return false;" value="View Graph" > View Graph </button>
         </div>

         <div id="txtHint" style="z-index: 1; left: 220px; top: 250px; position: absolute; margin-top: 0px">        
         </div>

   </body>
</html>

ajax 调用中的 ajax_graph_temp.php 调用是:

<?php
$mysqli =mysqli_connect('127.0.0.1:3306', 'root', 'root', 'test');
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: ".mysqli_connect_error();
}
  $result = $mysqli->query('SELECT * FROM view_name');

  $rows = array();
  $table = array();
  $table['cols'] = array(
    array('label' => 'pcount', 'type' => 'string'),
    array('label' => 'ncount', 'type' => 'number')
);
    /* Extract the information from $result */
    foreach($result as $r) {
      $temp = array();
      $temp[] = array('v' => (string) $r['ind_type']); 
      $temp[] = array('v' => (int) $r['Index_val']); 
      $rows[] = array('c' => $temp);
    }

$table['rows'] = $rows;

// convert data into JSON format
//$jsonTable = json_encode($table);

$jsonTable = json_encode($table);

echo $jsonTable;
?>

localhost 和 ec2 实例上的一切都相同。问题可能出在哪里?我在任何地方都犯错了吗?

4

0 回答 0