0

こんにちは、Google積み上げ縦棒グラフを試しています。しかし、解決できなかった次のエラーが発生していました。エラーは「Uncaught TypeError: null のプロパティ 'type' を読み取れません」です。

ここに私のコード

<html>
 <head>
    <title></title>      
     </head>  
     <?php  $con=mysql_connect("localhost","root", "innernet") or die("Failed to connect with database!!!!");
            mysql_select_db("mobiledb", $con); 



        $user= $_GET['user'];

        //echo $user;

       $response["cols"] = array();    
       // $news = array();
        //$news["id"] = "";
        //$news["label"] = "ID";                                           
        //$news["type"] = "string";                                           

        //array_push($response["cols"], $news);


        array_push($response["cols"], $news);
        $news = array();
        //$news["id"] = "";
        //$news["label"] = "Q9a";                                           
        $news["type"] = "number";                                           

        array_push($response["cols"], $news);       
         $news = array();
        //$news["id"] = "";
        //$news["label"] = "Q9b";                                           
        $news["type"] = "number";                                           

        array_push($response["cols"], $news);
       // $news = array();
      //  $news["id"] = "";
        //$news["label"] = "ts";                                           
      //  $news["type"] = "number";                                           

       // array_push($response["cols"], $news);       


        $result = mysql_query("SELECT `Q9a`, `Q9b` FROM goaltest WHERE id='$user'") or die(mysql_error());

        if (mysql_num_rows($result) > 0)
        {       
            $response["rows"] = array();    $table = array();   $rows = array();  
            while ($row = mysql_fetch_array($result))
            {        
                $temp = array();           
                //$temp[] = array('v' => (string) $row['id']);          
                $temp[] = array('v' => (int) $row['Q9a']);
                $temp[] = array('v' => (int) $row['Q9b']);
                //$temp[] = array('v' => (int) $row['ts']);

                array_push($response["rows"], array('c' => $temp));                                      
            }            
            //echo json_encode($response);             
        }



    ?>

    <!--Load the AJAX API -->
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
     google.load("visualization", "1.0", {packages:["imagechart"]});
    </script>
    <script type='text/javascript'>
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var response = '<?php echo json_encode($response); ?>';     alert(' hi ' + response);            
        var obj = eval ("(" + response + ")");
        var dataTable = new google.visualization.DataTable(response);


        var options = {cht: 'bvs', chs: '300x125', colors:['#4D89F9','#C6D9FD'],
          chds:'0,160', chxl:'0:|oranges|apples|pears|bananas|kiwis|'};

        var chart = new google.visualization.ImageChart(document.getElementById('bar_div'));
        chart.draw(dataTable, options);
      }
    </script>

  <body>
    <div id='bar_div'></div>
  </body>
</html>

だから誰かこれを解決する方法を教えてください

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

    <!--Load the AJAX API -->
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
     google.load("visualization", "1.0", {packages:["imagechart"]});
    </script>
    <script type='text/javascript'>
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var response = '{"cols":[null,{"type":"number"},{"type":"number"}],"rows":[{"c":[{"v":12},{"v":23}]},{"c":[{"v":37},{"v":55}]}]}';     alert(' hi ' + response);            
        var obj = eval ("(" + response + ")");
        var dataTable = new google.visualization.DataTable(response);


        var options = {cht: 'bvs', chs: '300x125', colors:['#4D89F9','#C6D9FD'],
          chds:'0,160', chxl:'0:|oranges|apples|pears|bananas|kiwis|'};

        var chart = new google.visualization.ImageChart(document.getElementById('bar_div'));
        chart.draw(dataTable, options);
      }
    </script>

  <body>
    <div id='bar_div'></div>
  </body>
</html> 
4

1 に答える 1

3

(@asgallant はおそらく既に正しく推測しています。) 最初の array_push(... $news) では、$news はまだ定義されていません。したがって、応答変数の「cols」プロパティの最初の配列要素は null です。最初の array_push をコメントアウトしたいだけかもしれません。

于 2013-08-07T23:40:17.030 に答える