Created
October 18, 2012 19:09
-
-
Save melodymorgan/3914145 to your computer and use it in GitHub Desktop.
Rickshaw Update Graph Realtime Data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var seriesData = [ [{ x: 0, y: 40 }, { x: 1, y: 49 }, { x: 2, y: 17 }, { x: 3, y: 42 }] ]; | |
var graph = new Rickshaw.Graph( { | |
element: document.getElementById("chart"), | |
width: 940, | |
height: 250, | |
renderer: 'area', | |
stroke: true, | |
series: [ | |
{ | |
color: 'steelblue', | |
data: seriesData[0], | |
name: 'SMS per minute' | |
} | |
] | |
}); | |
graph.render(); | |
var getLatestData = function(){ | |
jQuery.ajax({ | |
url: "/data.json", | |
type: "GET", | |
data: { | |
campaign_id : <?= $campaignId; ?>, | |
most_recent : mostRecent | |
}, | |
dataType: "json", | |
success: function(newData, textStatus, jqXHR){ | |
seriesData[0].push( { x: newData.x, y: newData.y } ); | |
graph.update(); | |
} | |
}); | |
}; | |
setInterval( function() { | |
getLatestData(); | |
}, 60000 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment