Giter VIP home page Giter VIP logo

eon-chart's Introduction

Please note that this project is no longer actively maintained or accepting Pull Requests. The EON library remains available on npm, bower, or through hotlink.


EON Charts

Realtime animated graphs with PubNub and C3.

Examples

Installing

Hotlink

<script type="text/javascript" src="https://pubnub.github.io/eon/v/eon/1.0.0/eon.js"></script>
<link type="text/css" rel="stylesheet" href="https://pubnub.github.io/eon/v/eon/1.0.0/eon.css"/>

Bower

bower install eon-chart --save

Check out our bower example.

NPM

npm install eon-chart --save

Check out our webpack example.

Quick Start

Plug your normal C3 config into the generate param. Supply an array of PubNub channel in channels param. eon.chart returns the normal C3 chart object.

<div id="chart"></div>
<script>
  var pubnub = new PubNub({
    publishKey:   'demo', // replace with your own pub-key
    subscribeKey: 'demo' // replace with your own sub-key
  });

  eon.chart({
    pubnub: pubnub,
    channels: ["c3-spline"],
    generate: {
      bindto: '#chart',
      data: {
        labels: true
      }
    }
  });
</script>

That's it! Now you can publish messages to the same channel and they'll render in the graph.

var pubnub = new PubNub({
  publishKey:   'demo', // replace with your own pub-key
  subscribeKey: 'demo' // replace with your own sub-key
});

setInterval(function(){
  pubnub.publish({
    channel: 'c3-spline',
    message: {
      eon: {
        'Austin': Math.floor(Math.random() * 99),
        'New York': Math.floor(Math.random() * 99),
        'San Francisco': Math.floor(Math.random() * 99),
        'Portland': Math.floor(Math.random() * 99)
      }
    }
  });

}, 1000);

All chart data must exist within an object called eon. Also notice how the channel and channels matches in both examples.

Configuration

Parameter Value Default
channels An array of PubNub channels to subscribe to. Either channels or channelGroups must be supplied. false
channelGroups An array of PubNub channel groups to subscribe to. Either channels or channelGroups must be supplied. false
generate Your C3 chart generation config. undefined
flow Used to update spline charts over time series. false
limit The size of your buffer. How many values to display on the chart before shifting the first value off and appending a new value. This is not native to C3. 10
rate Interval at which new datapoints are drawn on the chart in milliseconds. 1000
history Fill the buffer by using PubNub history call to retrieve last limit messages. Requires PubNub storage to be enabled. false
xType Your x axis configuration. Can be "auto", "custom", "category", or false. Read more about xType below. "auto"
xId Your x axis source if xType == "custom" "x"
message A function to call everytime a PubNub message is recieved. See PubNub subscribe function(message, env, channel){}
transform Method for changing the payload format of your stream. See example function(m){return m}
connect A function to call when PubNub makes a connection. See PubNub subscribe function(){}
pubnub An instance of the PUBNUB javascript global. This is required when using your own keys. See the subscribeKey example. false
debug Log EON events to console as they happen false

More on Publishing Messages

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

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

http://www.pubnub.com/documentation/

Customize Your Graph

eon-chart works will all supported graph types in C3. Just check out the examples above.

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

X Axis Configuration

Automatic

eon-chart will automatically use the PubNub message timestamp for chart x values. This timestamp is recorded when a message is published to the PubNub data stream network. This is the case when xType is set to "auto".

Custom

If you'd like to supply your own Javascript timestamp, set xType to custom. Then, set xId to the x value that appears within your published messages. Any custom x must be a microtime date like 1465417017340.

var pubnub = new PubNub({
  publishKey:   'demo', // replace with your own pub-key
  subscribeKey: 'demo' // replace with your own sub-key
});

eon.chart({
  pubnub: pubnub,
  channels: ["c3-spline"], // the pubnub channel for real time data
  generate: {           // c3 chart object
    bindto: '#chart'
  },
  xType: 'custom',
  xId: 'x'
});

Notice how the code below publishes a key value pair called x with every message.

pubnub.publish({
  channels: 'c3-spline',
  message: {
    eon: {
      'x': new Date().getTime(),
      'Austin': Math.floor(Math.random() * 99)
    }
  }
});

Category

Eon charts supports both time series bar charts and point of time bar charts. If you'd like to represent a bar chart in a single point of time, supply xType: "category" and only the latest data will appear in the chart categorized by key. See examples/bar.html for an example.

Multiple Points Per Payload

It is possible to publish multiple plot points per payload. Rather than using the object name eon use the name eons and supply an Array. Because you use the eons property name, the library will know to loop through the array and plot each point.

Note that if publishing multiple points per payload, you must use xType: "custom" and supply an xId.

eons: [
  {
    x: new Date().getTime(),
    value: 1
  },
  {
    x: new Date().getTime(),
    value: 2
  }
]

Here's an example of data collected at 100ms increments, but only publishes every 1,000ms. Every payload includes 10 points with 100ms resolution. See a full example here.

setInterval(function(){
  var data = [];
  var date = new Date().getTime();

  for(var i = 0; i < 10; i++) {
      data.push({
          'pub_time': date + (100 * i),
          'Austin': Math.floor(Math.random() * 99)
      });
  }

  pubnub.publish({
    channels: [channel],
    message: {
      eons: data
    }
  });

}, 1000);

Disable

You can disable eon-chart modifications by setting xType to false. By default C3 will use an incremental x axis (1,2,3,4...).

Distributed Systems

You can publish from multiple sources into one chart. For example, you can graph the individual memory usage from 3 servers by supplying the same channel to your PubNub publish requests.

Check out our distributed chart example.

eon-chart's People

Contributors

darryncampbell-pubnub avatar ianjennings avatar pubnubcraig avatar stephenlb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eon-chart's Issues

support history with limit > 100

Setting history: true with limit > 100 returns a chart with a maximum of 100 data points.

The pubnub API will only return 100 history at a time; after that one must make multiple requests for paged results. There appears to be some code in eon to handle paging (around line 213 of pubnub-c3.js) but this code does not have help when limit > 100. Looking at the javascript storage and playback docs:

https://www.pubnub.com/docs/web-javascript/storage-and-history

When paging we should "set the start attribute to start timetoken value, and request again" but the eon code instead seems to set the end attribute to the end timetoken value. Swapping end for start at lines 172 and 214 seems to get eon behaving as I would expect for limit > 100 but I don't know if it has some unintended side affect for other cases.

memory leak reintroduced

Leaving a window open in the background for some time (minutes) then refocusing causes the window to white out. It does not become unresponsive but the window appears totally white.

Bower install problem; ECONFLICT Unable to find suitable version for d3

bower i eon-chart doesn't work. Does anyone know the reason?

$ bower i --save eon-chart
bower eon-chart#*               cached https://github.com/pubnub/eon-chart.git#0.6.4
bower eon-chart#*             validate 0.6.4 against https://github.com/pubnub/eon-chart.git#*
bower d3#~3.5.5                 cached https://github.com/mbostock-bower/d3-bower.git#3.5.17
bower d3#~3.5.5               validate 3.5.17 against https://github.com/mbostock-bower/d3-bower.git#~3.5.5
bower pubnub#~3.7.8             cached https://github.com/pubnub/javascript.git#3.7.23
bower pubnub#~3.7.8           validate 3.7.23 against https://github.com/pubnub/javascript.git#~3.7.8
bower visibilityjs#~1.2.1       cached https://github.com/ai/visibility.js.git#1.2.3
bower visibilityjs#~1.2.1     validate 1.2.3 against https://github.com/ai/visibility.js.git#~1.2.1
bower subsub#0.0.1              cached https://github.com/pubnub/subsub.git#0.0.1
bower subsub#0.0.1            validate 0.0.1 against https://github.com/pubnub/subsub.git#0.0.1
bower c3#0.4.11-rc4             cached https://github.com/masayuki0812/c3.git#0.4.11-rc4
bower c3#0.4.11-rc4           validate 0.4.11-rc4 against https://github.com/masayuki0812/c3.git#0.4.11-rc4
bower d3#<=3.5.0                cached https://github.com/mbostock-bower/d3-bower.git#3.5.0
bower d3#<=3.5.0              validate 3.5.0 against https://github.com/mbostock-bower/d3-bower.git#<=3.5.0
bower                        ECONFLICT Unable to find suitable version for d3

Modify background?

How can I change the background of a line chart? I'm looking to get something more like this:

screenshot_2017-02-19_08-38-05

Turn off points?

I have a line graph based off this project.

I'm wondering if I can turn off the data point circles, or change radius to 0? I just want each line to appear as a smooth line.

Custom color

Am new to pubnub and I find it very interesting however I can't find where customize the color of the chart. I'm using a pie chart.
How do I customize the pie chart color?

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.