Solved

how to avoid "Error: script stack space quota is exhausted" when loading a big table with a javascript

Posted on 2009-04-04
10
3,302 Views
Last Modified: 2013-12-07
I'm trying to run the following script using google's API. The script works perfectly, but as soon as I add too many rows (with the "data.setValue" command)  it does not work anymore in Firefox or IE. The final script should be able to load around 95,000 rows. I've read it has to do with the script stack space. With Opera I'm actually able to load the page (but it runs very slowly).

Is there a way to improve the loading of the data? thanks!!!!!!!!!!!!!!!!!
<html>
  <head>   
 
 <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 drawChart() {
        var data = new google.visualization.DataTable();
        data.addRows(95000);
        data.addColumn('string', 'ID');
        data.addColumn('number', 'year');
        data.addColumn('number', 'Sum1');
        data.addColumn('number', 'Sum2');
        data.addColumn('number', 'Sum3');
 
data.setValue(0, 0, 'a_1'); data.setValue(0, 1, 2000); data.setValue(0, 2, 0); data.setValue(0, 3, 5); data.setValue(0, 4, 400);
data.setValue(1, 0, 'a_1'); data.setValue(1, 1, 2001); data.setValue(1, 2, 1); data.setValue(1, 3, 11); data.setValue(1, 4, 880);
data.setValue(2, 0, 'a_1'); data.setValue(2, 1, 2002); data.setValue(2, 2, 2); data.setValue(2, 3, 16); data.setValue(2, 4, 1550);
data.setValue(3, 0, 'a_1'); data.setValue(3, 1, 2003); data.setValue(3, 2, 3); data.setValue(3, 3, 19); data.setValue(3, 4, 1690);
data.setValue(4, 0, 'a_1'); data.setValue(4, 1, 2004); data.setValue(4, 2, 4); data.setValue(4, 3, 23); data.setValue(4, 4, 1770);
data.setValue(5, 0, 'a_1'); data.setValue(5, 1, 2005); data.setValue(5, 2, 5); data.setValue(5, 3, 29); data.setValue(5, 4, 2400);
data.setValue(6, 0, 'a_1'); data.setValue(6, 1, 2006); data.setValue(6, 2, 6); data.setValue(6, 3, 32); data.setValue(6, 4, 2460);
data.setValue(7, 0, 'a_1'); data.setValue(7, 1, 2007); data.setValue(7, 2, 7); data.setValue(7, 3, 35); data.setValue(7, 4, 2520);
data.setValue(8, 0, 'a_1'); data.setValue(8, 1, 2008); data.setValue(8, 2, 8); data.setValue(8, 3, 41); data.setValue(8, 4, 2890);
data.setValue(9, 0, 'a_1'); data.setValue(9, 1, 2009); data.setValue(9, 2, 9); data.setValue(9, 3, 43); data.setValue(9, 4, 3170);
 
 
*************** ROWS REMOVED FROM ORIGINAL CODE *******************************
 
 
var chart = new google.visualization.MotionChart(document.getElementById('chart_div'));
        chart.draw(data, {'width': 1600, 'height': 700});
      }
    </script>
 
 </head>
 
  <body>
 <div id="chart_div"  style="width: 800px; height: 400px;"></div>
  </body>
</html>

Open in new window

0
Comment
Question by:catalini
  • 5
  • 3
  • 2
10 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 24072056
Hi,

Might be a silly question, but what are you trying to do that required 95k rows loaded through javascript?
From an end user perspective this cannot be anything other than unusable I would expect.
When you are doing some sort of calculation, you'd rather do them cached and serverside for both your server as your end users sake.

k/r

Arnoud
0
 

Author Comment

by:catalini
ID: 24072117
this is not developed for an end-user. I'd like to see the visualize the results for myself using google APIs. It's not a problem if it takes too long to load.
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 24072154
What kind of calculations and visualization? Do you need to have all your rows in memory, or can you do partial calculations, to save on memory usage?
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:catalini
ID: 24072208
it's using all the rows for a motion chart (see http://code.google.com/apis/visualization/documentation/gallery/motionchart.html)...

is there a way to expand the browser's script stack? I've got plenty of memory available (3GB!).

I've seen someone using an iframe trick, but I'm not sure how to implement it. Is there a better way to input the data than mine? Maybe from a csv file?

thanks!!!
0
 
LVL 49

Accepted Solution

by:
Roonaan earned 500 total points
ID: 24072243
The api mentions that you can use CSV or JSON as a data source. I don't see them mentioning anything on the amount of data though

http://code.google.com/intl/nl/apis/visualization/documentation/dev/implementing_data_source.html
0
 

Author Comment

by:catalini
ID: 24072253
I wasn't able to load it using their csv example. I'm running the script locally on a html page of about 12MB...
0
 

Expert Comment

by:ProjectRAIN
ID: 24323674
Hi,

I'm actually having the same problem.
But as for my scenario, I like to grab a template file remotely using
jquery ajax, the also grab the data also using jquery - ajax in json format.
then bind them both template and data for display.
In theory this binding seems faster, there's just a "but"

the problem occurs when I try to retrieved bunch of records.

according to JQuery devs. they won't fix this or find another way for it.
http://dev.jquery.com/ticket/3250

but i've tried using the "complete" callback instead but still having the same
problem because i still need to convert it to string for the template binding.

Hope there's really a solution out there!

Thanks!
0
 

Author Comment

by:catalini
ID: 24378635
using Opera instead of Firefox or IE solved the problem.
0
 

Author Comment

by:catalini
ID: 24378674
no solution was posted.
0
 

Expert Comment

by:ProjectRAIN
ID: 25960022
this is due to data byte size downloaded from the server to the client side(browser) which the browser(FF) has smaller limit to carry the data in the Javascript.

to reproduce this error, you grab a large size of data and assign it to your javascript variable.
sorry, i forgot the limit set by FF.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question