Error In IE 6 & 7: Every row given must be either null or array.

1,258 views
Skip to first unread message

Nirav

unread,
Jan 6, 2010, 6:29:40 AM1/6/10
to Google Visualization API
Hi,

I am facing problem with Google Visualization API only in IE. In
Firefox works properly.please help me out to solve the problem.i am
integrating motion chart in joomla.please check the sample code below.

function important_issue_operation($option , $chart)
{
$db =& JFactory::getDBO();

?>
<div align="center" class="contentheading"> <?php echo $chart; ?></
div>
<script type="text/javascript" src="http://www.google.com/jsapi"></
script>
<script type="text/javascript">
google.load('visualization', '1', {'packages':['motionchart']});
google.setOnLoadCallback(drawChart);

/*---------------------- Function Draw Chart starts Here
-------------------------*/
function drawChart()
{
var data = new google.visualization.DataTable();
data.addColumn('string', 'District');
data.addColumn('number', 'Year');
data.addColumn('number', 'Major');
data.addColumn('number', 'Minor');
<?php

for($yr=2007;$yr<=2008;)
{
for($dist=1;$dist<=34;$dist++)
{

$qry = "select value from table1 where year=$yr and
district_id=$dist and breed=22";
$res= $db->setQuery($qry);
$total_major = $db->loadResult($res);

$qry1 = "select value from table1 where year=$yr and
district_id=$dist and breed=23";
$res1= $db->setQuery($qry1);
$total_minor = $db->loadResult($res1);

$qry = "select district_name from table2 where id=$dist";
$res= $db->setQuery($qry);
$district = $db->loadResult($res);


?>
data.addRows([
['<?php echo $district;?>',<?php echo $yr;?>,<?php echo
$total_major;?>,<?php echo $total_minor;?>],
]);


<?php }

$yr=$yr+1;
}?>

var chart = new google.visualization.MotionChart
(document.getElementById('chart_div'));
chart.draw(data, {width: 700, height:450});
}
/*-------------- Draw Chart Ends Here
---------------------------------------- */
</script>
<div id="chart_div" style="width: 700px; height: 450px;"></div>
<?php
}


JR

unread,
Jan 28, 2010, 1:27:33 PM1/28/10
to Google Visualization API
I came here looking for a solution to this problem, but ended up
solving it myself. For anyone else having this issue, the problem is
the trailing comma on the last row in the addRows call. For example
(just to be completely clear):

data.addRows([
[{v:"1", f:"Boss"}, "", ""],
[{v:"2", f:"Employee 1"}, "1", ""],
[{v:"3", f:"Employee 2"}, "1", ""],
]);

...will error out in IE because of the comma on the last row. But
this:

data.addRows([
[{v:"1", f:"Boss"}, "", ""],
[{v:"2", f:"Employee 1"}, "1", ""],
[{v:"3", f:"Employee 2"}, "1", ""]
]);

...works fine, after taking out the last comma. IE thinks there's one
more empty item in the array, I guess.

Gerard Flanagan

unread,
Jan 28, 2010, 1:59:45 PM1/28/10
to google-visua...@googlegroups.com
JR wrote:
> I came here looking for a solution to this problem, but ended up
> solving it myself. For anyone else having this issue, the problem is
> the trailing comma on the last row in the addRows call. For example
> (just to be completely clear):
>
> data.addRows([
> [{v:"1", f:"Boss"}, "", ""],
> [{v:"2", f:"Employee 1"}, "1", ""],
> [{v:"3", f:"Employee 2"}, "1", ""],
> ]);
>
> ...will error out in IE because of the comma on the last row. But
> this:
>
> data.addRows([
> [{v:"1", f:"Boss"}, "", ""],
> [{v:"2", f:"Employee 1"}, "1", ""],
> [{v:"3", f:"Employee 2"}, "1", ""]
> ]);
>
> ...works fine, after taking out the last comma. IE thinks there's one
> more empty item in the array, I guess.
>
>

Hi,

if you're not aware of it, jslint will pick up on these trailing commas
(among other things):

www.jslint.com

regards

G.F.

Nirav Desai

unread,
Jan 29, 2010, 8:15:57 AM1/29/10
to google-visua...@googlegroups.com
Hi Gerard,

         Thank you very much for solving my problem.

Thanks,
Nirav Desai.



--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.


Vincent Wansink

unread,
Feb 25, 2016, 5:25:27 PM2/25/16
to Google Visualization API
Another potential cause for this error is if you're passing a string instead of an array to the addRows function.  This would be common if you're generating the array some other way and passing it in.  In this case you'll need to JSON.parse it, like so:

data.addRows(JSON.parse(dataarray));

Another important note here, if you're generating this array as a string, you must make sure you're using single quotes around the array and double quotes around the string elements inside the array.  If you do it the other way around, it won't work.

In other words, your string should look like:
'[["Jan", 33,42], ["Feb", 9,41], ["Mar", 0,43]]'


Not

"[['Jan', 33,42], ['Feb', 9,41], ['Mar', 0,43]]"


Reply all
Reply to author
Forward
0 new messages