UNPKG

1.53 kBJavaScriptView Raw
1/* If you have not signed up for Plotly you can do so using https://plot.ly
2 * or see the example signup.js. Once you do, populate the config.json in this
3 * example folder!
4 */
5var config = require('./config.json')
6 , username = config['user']
7 , apikey = config['apikey']
8 , token = config['token']
9 , Plotly = require('../.')(username, apikey)
10 , Signal = require('random-signal')
11
12
13// build a data object - see https://plot.ly/api/rest/docs for information
14var data = {
15 'x':[] // empty arrays since we will be streaming our data to into these arrays
16 , 'y':[]
17 , 'type':'scatter'
18 , 'mode':'lines+markers'
19 , marker: {
20 color: "rgba(31, 119, 180, 0.96)"
21 }
22 , line: {
23 color:"rgba(31, 119, 180, 0.31)"
24 }
25 , stream: {
26 "token": token
27 , "maxpoints": 100
28 }
29}
30
31// build you layout and file options
32var layout = {
33 "filename": "streamSimpleSensor"
34 , "fileopt": "overwrite"
35 , "layout": {
36 "title": "streaming mock sensor data"
37 }
38 , "world_readable": true
39}
40
41/*
42 * Call plotly.plot to set the file up.
43 * If you have included a streaming token
44 * you should get a "All Streams Go!" message
45 */
46
47Plotly.plot(data, layout, function (err, resp) {
48 if (err) return console.log("ERROR", err)
49
50 console.log(resp)
51
52 var plotlystream = Plotly.stream(token, function () {})
53 var signalstream = Signal({tdelta: 100})
54
55
56 plotlystream.on("error", function (err) {
57 signalstream.destroy()
58 })
59
60 // Okay - stream to our plot!
61 signalstream.pipe(plotlystream)
62})