Skip to content

Instantly share code, notes, and snippets.

@ToeJamson
Created January 28, 2015 16:51
Show Gist options
  • Select an option

  • Save ToeJamson/484c8665da614092b991 to your computer and use it in GitHub Desktop.

Select an option

Save ToeJamson/484c8665da614092b991 to your computer and use it in GitHub Desktop.
Stream Data to Create Realtime Charts w/ D3.js and Rickshaw
<script src="http://cdn.pubnub.com/pubnub.min.js"></script>
<script src="../vendor/d3.v3.js"></script>
<script src="../rickshaw.min.js"></script>
<script src="../src/js/Rickshaw.Fixtures.PubNub.js"></script>
<div id="chart"></div>
<script>
var graph = new Rickshaw.Graph( {
element: document.getElementById("chart"),
width: 900,
height: 500,
renderer: 'area',
stroke: true,
preserve: true,
series: [
{
color: 'steelblue',
name: 'Cats',
data: []
},
{
color: 'lightblue',
name: 'Dogs',
data: []
}
]
});
graph.render();
</script>
<script>
new Rickshaw.Fixtures.PubNub({
channel: 'rickshaw-channel-1',
graph: graph
});
</script>
{
y: [
Math.random() * 99,
Math.random() * 99
],
x: new Date().getTime()
}
var pubnub = PUBNUB.init({
publish_key: 'demo',
subscribe_key: 'demo'
});
setInterval(function(){
pubnub.publish({
channel: 'rickshaw-channel-1',
message: {
y: [
Math.random() * 99,
Math.random() * 99
],
x: new Date().getTime()
}
})
}, 1000);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment