Error in IE: Argument given to addRows must be either a number or an array

2,098 views
Skip to first unread message

crawler

unread,
Feb 12, 2010, 8:47:34 AM2/12/10
to Google Visualization API
I'm getting the error message "Argument given to addRows must be
either a number or an array" in IE8 and I get reports of the same
error message in other versions as well. I could not find anything
about this problem. I'm sending both the function I use to draw with
and the data.

My code looks like this:
var data = new google.visualization.DataTable();
data.addColumn('string', 'Distance');
data.addColumn('number', 'Elevation');

data.addRows(callback.data);
var chart = new
google.visualization.AreaChart(document.getElementById('contourLine'));
chart.draw(data, {
width: '100%', //684
height: 250,
pointSize: 0,
min: 0,
axisFontSize: 12,
legend: 'none',
colors: ['#177245'],
title: 'Höjdkurva',
titleX: 'distans (km)',
titleY: 'hojd (m)'
});

And callback is an javascript object created from a JSON request from
my server, and callback.data is an array, see bellow.
{"code":1,"data":[["53",26],["65",25],["87",26],["124",24],["182",23],
["203",23],["233",23],["291",25],["364",24],["369",24],["383",24],
["404",26],["447",24],["477",24],["543",25],["561",24],["581",25],
["614",27],["722",25],["733",25],["775",22],["822",24],["879",26],
["890",24],["909",23],["930",23],["994",23],["1046",23],["1077",23],
["5113",32],["5122",33],["5127",35],["5128",36],["5175",36],["5273",
34],["5309",34],["5333",32],["5357",31],["5398",30]]}

Viz Kid

unread,
Feb 15, 2010, 6:36:06 AM2/15/10
to google-visua...@googlegroups.com
Hi.

It wasn't clear from your post if this happens only in IE or other browsers as well (meaning if you tested it on other browsers)?
Can you also give a live example of your code which doesn't work?

Best,
  Viz Kid


--
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.


crawler

unread,
Feb 15, 2010, 7:09:41 AM2/15/10
to Google Visualization API
Hi

The code works in all browser except for IE6, 7and 8. I don't know if
I'm doing something wrong or if it's a bug in the Visualization
library. But I could not find any bug report and I can't be the first
one to have had this problem.So I though I did something wrong. The
JSON object is what I call "callback" in my code above, and
"callback.data" is an array of arrays (that is an array of datapoints
which I load with addRows).

On Feb 15, 12:36 pm, Viz Kid <viz...@google.com> wrote:
> Hi.
>
> It wasn't clear from your post if this happens only in IE or other browsers
> as well (meaning if you tested it on other browsers)?
> Can you also give a live example of your code which doesn't work?
>
> Best,
>   Viz Kid
>

> > google-visualizati...@googlegroups.com<google-visualization-api%2Bunsu...@googlegroups.com>

Viz Kid

unread,
Feb 15, 2010, 7:26:48 AM2/15/10
to google-visua...@googlegroups.com

I just tried it now using IE8 with some rows which works fine.
If you can send us a live page where you see the problem we can try to help you better.

  Viz Kid


To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.

crawler

unread,
Feb 15, 2010, 7:52:43 AM2/15/10
to Google Visualization API
Hi

You can see the problem in this page for example:
http://www.opentrailmap.net/viewtrail.php?id=4

I'm loading the data on the page with Mootools request.JSON. It's the
second JSON request that loads the graph data.

In gMap.js: loadGraph is the function which makes the JSON request,
and drawContourLine is the callback function which initializes the
graph.

If you like I can upload a version of the javascript which is easier
to read.

On Feb 15, 1:26 pm, Viz Kid <viz...@google.com> wrote:
> I just tried it now using IE8 with some rows which works fine.
> If you can send us a live page where you see the problem we can try to help
> you better.
>
>   Viz Kid
>

> > <google-visualization-api%2Bunsu...@googlegroups.com<google-visualization-api%252Buns...@googlegroups.com>

Viz Kid

unread,
Feb 15, 2010, 8:29:45 AM2/15/10
to google-visua...@googlegroups.com

Hi.

It is indeed hard to follow the JS this way.
Regardless, I took the returned response you get and plugged it into a standard html, viewed it in IE8 and it works fine. So I think it means you have some other problem in the page that somehow causes this. Maybe you should try and write to the screen what the actual parameter that you are passing to the draw.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>
      Google Visualization API Sample
    </title>
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load('visualization', '1', {packages: ['gauge']});
    </script>
    <script type="text/javascript">
      function drawVisualization() {
        // Create and populate the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Label');
        data.addColumn('number', 'Value');
        var response = {"code":1,"data":[["86",30],["130",35],["146",36],["198",40],["255",42],["313",45],["342",47],["393",48],["449",52],["491",56],["557",57],["595",57],["683",60],["734",62],["743",63],["774",63],["834",65],["869",64],["918",61],["988",64],["1018",65],["1078",63],["1115",63],["1195",61],["1255",62],["1295",62],["1350",60],["1375",59],["1415",57],["1455",58],["1508",48],["1570",48],["1607",49],["1659",50],["1700",48],["1739",44],["1831",39],["1950",24],["2051",24],["2141",27],["2189",26],["2250",26],["2322",29],["2405",30],["2514",31],["2555",36],["2630",35],["2658",35],["2767",35],["2842",33],["2922",48],["2967",50],["3133",49],["3319",48],["3379",52],["3396",55],["3494",52],["3599",49],["3779",51],["3842",54],["3943",50],["3966",49],["4148",52],["4183",52],["4259",49],["4402",48],["4510",41],["4694",36],["4745",36],["4806",31],["4908",34],["4968",37],["5041",36],["5091",36],["5128",37],["5198",33],["5282",29],["5337",35],["5407",38],["5594",45],["5739",48],["5890",55],["5977",52],["6086",59],["6168",52],["6349",44],["6402",43],["6435",42],["6532",40],["6571",39],["6746",48],["6841",47],["7070",58],["7137",58],["7224",61],["7298",60],["7346",60],["7400",60],["7424",59],["7480",54],["7529",46],["7564",28],["7626",32],["7711",28],["7761",19],["7794",21],["7832",25],["7893",28],["8018",32],["8300",34],["8366",28],["8435",9],["8580",15],["8639",17],["8706",16],["8772",18],["8832",23],["8950",23],["9025",24],["9033",25],["9129",25],["9236",25],["9407",25],["9521",24],["9543",25],["9604",31],["9651",32]]}

        data.addRows(response.data);
  
        // Create and draw the visualization.
        new google.visualization.Gauge(document.getElementById('visualization')).
            draw(data, null);
      }
      

      google.setOnLoadCallback(drawVisualization);
    </script>
  </head>
  <body style="font-family: Arial;border: 0 none;">
    <div id="visualization" style="width: 900px; height: 900px;"></div>
  </body>
</html>

  Viz Kid

To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.

crawler

unread,
Feb 15, 2010, 9:01:34 AM2/15/10
to Google Visualization API
Hi

Thanks for your help, I will do some more debuging to see what is
wrong.

Once more, thanks for your help.

On Feb 15, 2:29 pm, Viz Kid <viz...@google.com> wrote:
> Hi.
>

> > > > <google-visualization-api%2Bunsu...@googlegroups.com<google-visualization-api%252Buns...@googlegroups.com>
> > <google-visualization-api%252Buns...@googlegroups.com<google-visualization-api%25252Bun...@googlegroups.com>

crawler

unread,
Feb 19, 2010, 3:45:53 AM2/19/10
to Google Visualization API
Hi

I would just like to explain what the problem was. It was totaly my
fault but just in case someone makes the same misstake...

I used Google jsapi to load the graph component, and then I set an
google.SetOnLoadCallback to know when it was loaded.
At the same time I used a "doomready" callback. The problem was the in
IE the SetOnLoadCallback fas called before the doomready call. And in
my case there was some parts of the webpage that had not been
initialized yet.

To solve the situation I keeped the "doomready" callback and used the
"Dynamic Loading" functionality instead.

Once again, thanks for the good support, cheers!

> > > > > > >                title: 'Höjdkurva',

Abhik Bhowmik

unread,
Mar 28, 2014, 8:16:42 AM3/28/14
to google-visua...@googlegroups.com
Hi,
      I faced same error for this code..
"Message: If argument is given to addRow, it must be an array, or null"
kindly help me to solve. after button click rows created automatically in table. just need this.
-------------------------------------------  
var v1=document.getElementById('txt1').value;
 a= new Array();
 a = v1.split("*");
 alert(a[0]);
  var numRows = a.length;
       alert(numRows);

          for (var i = 0; i < 1; i++)
               data.addRow(a[i]); 

<body>
<input type="text" id="txt1" value="['Mike', {v: 10000, f: '$10,000'}, '28/05/2013']*['Jim',   {v:8000,   f: '$8,000'}, '27/03/2006'] ">
<input type="button" text="click me" onclick="drawTable()" >
<div id='table_div'></div>
  </body>
---------------------------------------------------

asgallant

unread,
Mar 28, 2014, 10:36:35 AM3/28/14
to google-visua...@googlegroups.com
This line:

a = v1.split("*");

splits the string into an array of strings, not an array of arrays.  If you replace the "*"s with commas, you can use javascript's JSON parser to build your data array:

v1 = v1.replace(/\*/g, ',');
a = JSON.parse(v1);

You can then add the data via the #addRows method:

data.addRows(a);

Abhik Bhowmik

unread,
Mar 29, 2014, 8:14:19 AM3/29/14
to google-visua...@googlegroups.com
Hello, 
        Thanks for replying. I never work with JSON. But i could not install json.js. so how can i do this.

Thanks & Regards,
Abhik Bhowmik
Mobile: +918794415116


--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/y4yvI6wTheQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.

asgallant

unread,
Mar 31, 2014, 11:37:19 AM3/31/14
to google-visua...@googlegroups.com
You do not need to install any special javascript to use the JSON methods - they are part of the standard javascript library.
To unsubscribe from this group and all its topics, send an email to google-visualization-api+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages