If you wrap the AJAX call in a function, you can use the setTimeout or 
setInterval functions (depending on how exactly you want this to work, they 
won't act equivalently).

Using setTimeout:

function foo () {
    $.ajax({
        // stuff
        success: function (response) {
            //...
            setTimeout(foo, 5000); // call foo again 5 seconds after the 
AJAX call returns
        }
    });
}

using setInterval:

function foo () {
    $.ajax({/*...*/});
}
setInterval(foo, 5000); // call foo every 5 seconds

The difference is that the setInterval method will make the AJAX call every 
5 seconds, regardless of whether or not your data source has returned yet 
(and because of the asynchronous nature of AJAX, it is actually possible to 
get the second set of data returned before the first set, so you have to be 
careful and track which data set is actually the most recent). 
 Implementing tracking with this method can be a bit tricky, but done 
properly, you are more likely to have the freshest data in the chart at any 
given time using this method than using the setTimeout (which only fetches 
the next set of data after the current call returns - any hangup or delay 
in one call to the server will delay the next call as well).

On Friday, July 12, 2013 7:55:34 AM UTC-4, Benjamin Bandali wrote:
>
> Hi,
>
> I have a line chart that looks like this: 
>
> * $.ajax({*
> * url : "list/",*
> * type : "GET",*
> * data : ({*
> * categoryName : name + "",*
> * toTime : todayString + "",*
> * fromTime : yesterdayString + ""*
> * }),*
> * aync : true,*
> * dataType : "json",*
> * error : function(e) {*
> * alert(e.message + "ERROR ");*
> * },*
> * success : function(response) {*
> * drawTablePresentStatus(name);*
> * var jsonData = response;*
> * *
> * drawChart2(jsonData, response);*
> * jsonData.tableData = {*
> * "c1" : "data"*
> * };*
> * // drawTablePresentStatus(jsonData.tableData);*
> *
> *
> * }*
> * });*
> *};*
> *function drawChart2(jsonData, response) {*
> *
> *
> * var data = new google.visualization.DataTable();*
> * data.addColumn('datetime', 'timestamp');*
> * data.addColumn('number', response[0].categoryName);*
> * data.addColumn({*
> * type : 'string',*
> * role : 'tooltip'*
> * });*
> * *
> * *
> * *
> * *
> * var dt;*
> * for ( var i in jsonData) {*
> * dt = jsonData[i].toTime;// .split(/\-|\s/);*
> * dat = new Date(dt);*
> * var value = new Number(jsonData[i].value);*
> * *
> * var dateStr = dt;*
> * var a=dateStr.split(" ");*
> * var d=a[0].split("-");*
> * var t=a[1].split(":");*
> * var date = new Date(d[0],(d[1]-1),d[2],t[0],t[1],t[2]);*
> *
> *
> * data.addRow([ date, parseInt(value, 10),*
> *              "Category: "+response[0].categoryName+"\n"+"Status: 
> "+jsonData[i].statusColor.toString()+"\n"+"Date & Time: "+dt.toString()]);
> *
> * }*
> * *
> * var options = {*
> * animation :{*
> * duration : 50000,*
> * easing : 'in'*
> * },*
> *
> *
> * title : name + " (" + response[0].unit + ")",*
> *
> *
> * hAxis : { viewWindow : null},*
> *
> *
> * hAxis :{ viewWindowMode : 'pretty'},*
> * *
> * pointSize : 3*
> *
> *
> * };*
> *
> *
> Can I do so this graph refreshes automatically somehow? for N seconds, It 
> fetches data from the datase if its worth mentioning. Thanks in forehand.
>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to