Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Commit 1318658

Browse files
committed
Merge pull request #20 from plotly/multiple-streams
Add multiple trace stream example
2 parents 28243e7 + cc9aabb commit 1318658

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

examples/streaming-multiple-traces.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
var config = require('./config.json'),
2+
username = config.user,
3+
apikey = config.apikey,
4+
tokens = config.tokens,
5+
Plotly = require('../.')(username, apikey),
6+
Signal = require('random-signal');
7+
8+
function initTrace(i) {
9+
return {
10+
x: [], // init. data arrays
11+
y: [],
12+
type: 'scatter',
13+
mode: 'lines+markers',
14+
stream: {
15+
"token": tokens[i],
16+
"maxpoints": 100
17+
}
18+
};
19+
}
20+
21+
var data = [0, 1].map(initTrace);
22+
23+
var layout = {
24+
filename: "stream-multiple-traces",
25+
fileopt: "overwrite",
26+
layout: {
27+
title: "streaming mock sensor data"
28+
},
29+
world_readable: true
30+
};
31+
32+
33+
Plotly.plot(data, layout, function (err, resp) {
34+
if (err) return console.log("ERROR", err, data);
35+
console.log(resp);
36+
37+
[0, 1].forEach(function(i) {
38+
var plotlystream = Plotly.stream(tokens[i], function() {}),
39+
signalstream = Signal({tdelta: 100});
40+
41+
plotlystream.on("error", function (err) { signalstream.destroy(); });
42+
43+
signalstream.pipe(plotlystream);
44+
});
45+
46+
});

0 commit comments

Comments
 (0)