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,299 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

912 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now