API error "not an array"

1,243 views
Skip to first unread message

smre...@gmail.com

unread,
Nov 12, 2014, 1:58:36 PM11/12/14
to google-visua...@googlegroups.com
Long story short, I use Alpha 5 as my development tool and was able test using Google Charts API per some of your examples (and assistance from a previous post).  So using your static chart example, I modified my code to connect to our SQL database and retrieve data to display in the chart, rather than using static, hard coded data.  I can confirm it's connecting to our data source and returning the correct data by stepping through my code and checking the values of the chart data, but the chart doesn't get rendered.   I get a pop up that says:


 
When I check the Firefox debugger, it says:
ERROR NOT AN ARRAY
function hga(a,b){var c={};if(!ki(a))throw m("Not an array");

Here is my JavaScript function:

function drawChart() {
  
  var chartdata = {dialog.object}._data;
 
  var data = google.visualization.arrayToDataTable(
     chartdata
     );
    
  var options = {
    title : 'Cost of Quality',
    is3D: true,
  };
 
  var chart = new google.visualization.PieChart(document.getElementById('mychart'));
 
  chart.draw(data, options);
};


And the value of {dialog.object}._data = [['Type', 'Cost'],['CUSTOMER RETURN', 1405],¶['INTER-COMPANY', 100],¶['REWORK', 200],¶['SCRAP', 100],¶['SETUP SCRAP', 110],¶['VENDOR RETURN', 5],¶['WARRANTY RETURN', 800]];

Can anyone shed some light on this error?  I'm at a loss.  Thanks.


Sergey Grabkovsky

unread,
Nov 12, 2014, 2:11:21 PM11/12/14
to google-visua...@googlegroups.com
It's tough to say what's going on here and why it's failing, since it looks like your data is in fact an array. My guess is that your chartdata is an array encoded as a string. Could you perhaps do console.log(typeof chartdata) and report back what it says? Or even console.log(JSON.stringify(chartdata))?

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

smre...@gmail.com

unread,
Nov 12, 2014, 2:55:44 PM11/12/14
to google-visua...@googlegroups.com
Thanks for the quick reply Sergey.

Please forgive my ignorance, I'm literally just figuring out how to use the debugging tool today so I really am fumbling through it.  I added the 2 lines you mentioned to my javascript function and here's what I see in Firefox debugger.  Unfortunately it doesn't tell me much.  Am I not looking in the right place?:




On Wednesday, November 12, 2014 2:11:21 PM UTC-5, Sergey wrote:
It's tough to say what's going on here and why it's failing, since it looks like your data is in fact an array. My guess is that your chartdata is an array encoded as a string. Could you perhaps do console.log(typeof chartdata) and report back what it says? Or even console.log(JSON.stringify(chartdata))?

On Wed Nov 12 2014 at 1:58:38 PM <smre...@gmail.com> wrote:
Long story short, I use Alpha 5 as my development tool and was able test using Google Charts API per some of your examples (and assistance from a previous post).  So using your static chart example, I modified my code to connect to our SQL database and retrieve data to display in the chart, rather than using static, hard coded data.  I can confirm it's connecting to our data source and returning the correct data by stepping through my code and checking the values of the chart data, but the chart doesn't get rendered.   I get a pop up that says:


 
When I check the Firefox debugger, it says:
ERROR NOT AN ARRAY
function hga(a,b){var c={};if(!ki(a))throw m("Not an array");

Here is my JavaScript function:

function drawChart() {
  
  var chartdata = {dialog.object}._data;
 
  var data = google.visualization.arrayToDataTable(
     chartdata
     );
    
  var options = {
    title : 'Cost of Quality',
    is3D: true,
  };
 
  var chart = new google.visualization.PieChart(document.getElementById('mychart'));
 
  chart.draw(data, options);
};


And the value of {dialog.object}._data = [['Type', 'Cost'],['CUSTOMER RETURN', 1405],¶['INTER-COMPANY', 100],¶['REWORK', 200],¶['SCRAP', 100],¶['SETUP SCRAP', 110],¶['VENDOR RETURN', 5],¶['WARRANTY RETURN', 800]];

Can anyone shed some light on this error?  I'm at a loss.  Thanks.


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.

smre...@gmail.com

unread,
Nov 12, 2014, 2:57:33 PM11/12/14
to google-visua...@googlegroups.com

Sergey Grabkovsky

unread,
Nov 12, 2014, 2:57:56 PM11/12/14
to google-visua...@googlegroups.com
It seems like you forgot to paste the content of the debugger. If not, perhaps a screenshot would be more appropriate?

To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.

Sergey Grabkovsky

unread,
Nov 12, 2014, 3:02:48 PM11/12/14
to google-visua...@googlegroups.com
OK, it looks like your chartdata is undefined. Which is, in fact, not an array. It effectively means that the property _data is missing; which in turn means that something is iffy with your configuration. Please add the line console.log({dialog.object}) and post a screenshot of that, and perhaps I can help you further.

To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.

smre...@gmail.com

unread,
Nov 14, 2014, 11:09:19 AM11/14/14
to google-visua...@googlegroups.com
Hmmmm, that's an interesting thought!  I added the console line you requested and get the following.  I see that the properties section on the right DOES NOT list "_data" which puzzles me:

:



When I drill down on that first line and review the html, I can see the dialog data is set to my array and loaded with the data I am trying to chart (dialogId = DLG1 so the development tool renames it accordingly):

DLG1_DlgObj._data = [['Type', 'Cost'],['CUSTOMER RETURN', 1405],

['INTER-COMPANY', 100],
['REWORK', 200],
['SCRAP', 100],
['SETUP SCRAP', 110],
['VENDOR RETURN', 5],
['WARRANTY RETURN', 800]];;

Please let me know your thoughts as I am running out of time to get this completed.  Boss wants to purchase a charting tool and quite honestly, the Google Charts are much prettier and I would prefer we go this route.

Thanks again for all your help!
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsubscr...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Sergey Grabkovsky

unread,
Nov 14, 2014, 11:17:39 AM11/14/14
to google-visua...@googlegroups.com
The things you're talking about seem to be specific to your development tools/environment, which is another way of saying, I'm not really sure what you're talking about. It also appears that you either forgot to post the "properties section", so I don't really see what you're talking about either. Try doing console.log(JSON.stringify({dialog.object})) to log the JSON representation of your object to the console, and post back a screenshot.

The best help I can give you at this stage is that perhaps your data is being set after your chart is getting drawn. Try putting console.log calls right before your data is set and right before you actually attempt to use it. I bet that you'll see the latter first.

To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.

smre...@gmail.com

unread,
Nov 14, 2014, 1:21:47 PM11/14/14
to google-visua...@googlegroups.com
YOU ARE RIGHT!  If I call drawChart on a button click event it works so I am calling it in the wrong event which is obviously running BEFORE the chart data is being populated!  Thank you SO MUCH for all of your help!  I've learned a lot through the process and can confidently tell the boss that Google Charts is a go! 

Sergey Grabkovsky

unread,
Nov 14, 2014, 1:31:32 PM11/14/14
to google-visua...@googlegroups.com
You're welcome =) I'm glad you got it working!

To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages