Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit bbc0877

Browse files
signal stream example
1 parent 00c9305 commit bbc0877

4 files changed

Lines changed: 70 additions & 6 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
node_modules
22
*.log
3-
3+
config.json

examples/config.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"user" : "",
3-
"apikey" : "",
4-
"token" : ""
5-
}
2+
"user" : "",
3+
"apikey" : "",
4+
"token" : ""
5+
}

examples/signal-stream.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
*/
5+
var 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
14+
var 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
32+
var 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+
47+
Plotly.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+
})

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"version": "0.1.7",
44
"description": "Simple node.js wrapper for the plot.ly API",
55
"main": "plotly.js",
6-
"devDependencies": {},
6+
"devDependencies": {
7+
"random-signal": "0.0.2"
8+
},
79
"scripts": {
810
"test": "echo \"Error: no test specified\" && exit 1"
911
},

0 commit comments

Comments
 (0)