Skip to content

Instantly share code, notes, and snippets.

@melodymorgan
Created October 18, 2012 19:09
Show Gist options
  • Save melodymorgan/3914145 to your computer and use it in GitHub Desktop.
Save melodymorgan/3914145 to your computer and use it in GitHub Desktop.
Rickshaw Update Graph Realtime Data
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