A simple approach based on your exact code would be:
(function redraw() { drawAltitudeChart(); setTimeout(redraw, 20000); })();
For a more in-depth and customizable approach: (I did this with only basic knowledge of the API diagrams.)
function AltitudeChart() { this.chart = new google.visualization.LineChart( document.getElementById('curve_chart') ); } AltitudeChart.prototype = { draw: function() { var graph = []; downloadUrl('Map.php', function(data) { var xml = data.responseXML; var markers = xml.documentElement.getElementsByTagName("marker"); var dataTable = new google.visualization.DataTable(); var options = { title: 'Altitude (m above sea level)', curveType: 'function', legend: { position:'bottom' }, is3d: true }; for (var i = 0; i < markers.length; i++) { graph[i] = ['', parseInt(markers[i].getAttribute("alt"))]; } dataTable.addColumn('string', 'id'); dataTable.addColumn('number', 'Altitude'); dataTable.addRows(graph); this.chart.draw(dataTable, options); }); }, refreshDraw: function() { this.drawTimeout = setTimeout(function() { this.draw(); this.refreshDraw();
I am sure there is a better way to do this with a deeper knowledge of the charting API, but the logic should work.
source share