GithubHelp home page GithubHelp logo

pubnub-rickshaw's Introduction

PubNub + Rickshaw

Make your Rickshaw graphs realtime with PubNub.

Quickstart

new Rickshaw.Fixtures.PubNub({
  graph: graph,
  subscribe_key: 'demo',
  channel: 'rickshaw-channel-2',
  history: true,
  connect: init,
});
Parameter Value Default
graph Your Rickshaw.Graph. Works just like the extensions included in Rickshaw examples. undefined
subscribe_key Your PubNub subscribe_key demo
limit The size of your buffer. How many values on the x series to display before shifting data. 50
history Use PubNub history call to retrieve last limit messages. Requires PubNub storage to be enabled. false
ready This function fires once data has been retrieved from PubNub. Some extensions assume the graph will have data when they are initialized, so we ca n put them inside here. function(){}

Simple Example

Include the Javascripts within your file.

<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>

Define a Rickshaw chart element as normal.

<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>

Add PubNub Fixture.

<script>
new Rickshaw.Fixtures.PubNub({
  channel: 'rickshaw-channel-1',
  graph: graph
});
</script>

Kitchen Sink

Check out the PubNub Extension demo for an example of using the PubNub fixture within a complicated Rickshaw setup.

Note that you need to initialize other fixtures within our connection callback. Some fixtures will cause errors if they are initialized before there is data in the chart.

Publish Messages

This uses the included PubNub library to pubnub.publish() packets to the pubnub.subscribe() call waiting inside the Rickshaw framework.

Notice how the subscribe_key and channel matches.

You probably want to publish data from the back-end instead. Check out our docs for more info:

http://www.pubnub.com/docs

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>

Customize Your Graph

You can learn more about customizing your graph from the official Rickshaw docs.

Shutterstock Rickshaw

Rickshaw Copyright (C) 2011-2013 by Shutterstock Images, LLC

pubnub-rickshaw's People

Contributors

ianjennings avatar stephenlb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.