catalini
asked on
how to avoid "Error: script stack space quota is exhausted" when loading a big table with a javascript
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!!!!!!!!!!!!!!!!!
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>
ASKER
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.
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?
ASKER
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!!!
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!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I wasn't able to load it using their csv example. I'm running the script locally on a html page of about 12MB...
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!
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!
ASKER
using Opera instead of Firefox or IE solved the problem.
ASKER
no solution was posted.
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.
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.
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