Hi, how i can refresh chart without refresh all page ??
I use function refresh chart where i did clearAll(); and load data for graph
function refreshchart() {
chart.clearAll();
chart.load("/data/test.json","json");
setTimeout(refreshchart,60000);
}
setTimeout(refreshchart,60000);
i run setTimeout(refreshchart,60000); function on the first load page and in the refreshchart function but i think i have memory leak in this scheme.
How i can refresh only chart (not all page) correctly ??
Darya, but with each minutes, the memory that use my browser grows
i try it on the IE8 and Firefox
but i have simple page code
only one html table where i show the chart and javascript for create a chart
and add in java script this function for refresh chart each 60sec
function refreshchart() {
chart.clearAll();
chart.load("/data/test.json","json");
setTimeout(refreshchart,60000);
}
setTimeout(refreshchart,60000);
and after refreshing each min used memory grows …
gyper, to free memory, you have to use clearTimeout before executing a new setTimeout. Here is an example:
// Global var declaration
var myRef;
// Trigger refreshchart for the first time (try-catch is included “just in case”)
try{ clearTimeout(myRef); }
catch(err) {}
myRef = setTimeout(refreshchart,60000);
// Your refreshchart function
function refreshchart() {
try{ clearTimeout(myRef); }
catch(err) {}
myRef = setTimeout(refreshchart,60000);
chart.clearAll();
chart.load("/data/test.json",“json”);
}
That is correct: clearTimeout releases the memory taken by the related setTimeout. (Relationship is established by the reference variable: myRef).
If you don’t use clearTimeout, each time you call setTimeout it’ll use a new block of memory. As you are calling it every minute, in an hour you’ll be using 60 times more memory.