Populating Data Using Server-Side Code on IE8, 'this.G[...].c' is null or not an object

93 views
Skip to first unread message

lohenzo

unread,
Dec 17, 2011, 6:49:46 PM12/17/11
to Google Visualization API
I'm implementing google graph api on my site using the "Populating
Data Using Server-Side Code" tutorial (http://code.google.com/apis/
chart/interactive/docs/php_example.html) and it's working fine on
Chrome, Safari and Firefox but on IE8 show the next error:

'this.G[...].c' is null or not an object

and don't load the graph, anyone knows why? or what can i do?

asgallant

unread,
Dec 19, 2011, 12:25:14 PM12/19/11
to google-visua...@googlegroups.com
This is usually caused by an extra comma in an array or object.

lohenzo

unread,
Dec 19, 2011, 1:56:05 PM12/19/11
to Google Visualization API
do you mean in the json file?

lohenzo

unread,
Dec 19, 2011, 2:08:07 PM12/19/11
to Google Visualization API
Ok, got it! yes, i had an extra comma here

"rows": [
{"c":[{"v":"Mushrooms","f":null},{"v":3,"f":null}]},
{"c":[{"v":"Onions","f":null},{"v":1,"f":null}]},
{"c":[{"v":"Olives","f":null},{"v":1,"f":null}]},
{"c":[{"v":"Zucchini","f":null},{"v":1,"f":null}]},
{"c":[{"v":"Pepperoni","f":null},{"v":2,"f":null}]} (H E R E
T H E E X T R A C O M M A)
]

i'm generating the json file with a foreach loop, identifying the last
key and removing that comma was the solution. thanks!

asgallant

unread,
Dec 19, 2011, 2:40:16 PM12/19/11
to google-visua...@googlegroups.com
If you use PHP, a trick I use to get around that problem is to put each output row into an array first (leave out the commas) then use the implode function to glue the array pieces together with commas.  When you are dealing with JSON specifically, an even better solution is to put the data into an associative array and output it with the json_encode() function.  Ex:

$output = array (
    'rows' => array (
       array (
           'c' => array (
               array ('v' => 'Mushrooms', 'f' => null),
               array ('v' => 3, 'f' => null)
           ),
           'c' => array (
               array ('v' => 'Onions', 'f' => null),
               array ('v' => 1, 'f' => null)
           ),
           'c' => array (
               array ('v' => 'Olives', 'f' => null),
               array ('v' => 1, 'f' => null)
           ),
               'c' => array (
               array ('v' => 'Zucchini', 'f' => null),
               array ('v' => 1, 'f' => null)
           ),
           'c' => array (
               array ('v' => 'Pepperoni', 'f' => null),
               array ('v' => 2, 'f' => null)
           )
       )
    )
);
echo json_encode($output);
Reply all
Reply to author
Forward
0 new messages