function update_view() { var time1 = $("#time1").val(); var time2 = $("#time2").val(); var stat = $("#stat").val(); //var resolution = $("#resolution").val(); // seems to do nothing var resolution = 604800; var stat_obj = stat.split('.')[0] var stat_type = stat.split('.')[1] $("body").css("cursor", "progress"); $.ajax({ url: "http://node.sugarlabs.org/", data: { cmd: "stats", start: time1, end: time2, source: stat, resolution: resolution }, success: function( data ) { $("body").css("cursor", "default"); fixed_data = data[stat_obj].reduce( function(a,b,c) { a.push( [new Date ( b[0] * 1000 ) , b[1][stat_type]]); return a }, [] ); $('#chartdiv').empty(); $.jqplot('chartdiv', [fixed_data], { title:stat, axes: { xaxis: { renderer: $.jqplot.DateAxisRenderer, min:new Date( time1 * 1000), max:new Date( time2 * 1000), tickInterval: '1 month', tickOptions:{formatString:'%Y/%m/%d'} }, yaxis: { min:0 } }, cursor:{ show: true, zoom:true, showTooltip:false } } ); }, error: function() { $("body").css("cursor", "default"); alert("Error fetching statistics from node."); } }); } $(function() { // Make second input now $("#time2").val(Math.round((new Date()).getTime()/1000)); $("#update_btn").click(update_view) });