php - Google stacked column chart giving an error -


hi trying google stacked column charts. getting following error not able solve it. error "uncaught typeerror: cannot read property 'type' of null "

here code

<html>  <head>     <title></title>            </head>        <?php  $con=mysql_connect("localhost","root", "innernet") or die("failed connect 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` goaltest 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 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> 

so please 1 tell me how solve

<html>  <head>     <title></title>        </head>        <!--load 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>  

(@asgallant has guessed right already.) in first array_push(... $news) $news not yet defined. consequently, first array element under "cols" property in response variable null. maybe want comment out first array_push.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -