forked from plotly/plotly-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreaming-example.js
More file actions
26 lines (20 loc) · 789 Bytes
/
Copy pathstreaming-example.js
File metadata and controls
26 lines (20 loc) · 789 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'use strict';
var plotly = require('../.')('plotlyUsername','apiKey');
var initdata = [{x:[], y:[], stream:{token:'streamToken', maxpoints:200}}];
var initlayout = {fileopt : 'overwrite', filename : 'nodenodenode'};
plotly.plot(initdata, initlayout, function (err, msg) {
if (err) return console.log(err);
console.log(msg);
var stream1 = plotly.stream('streamToken', function (err, res) {
if (err) return console.log(err);
console.log(res);
clearInterval(loop); // once stream is closed, stop writing
});
var i = 0;
var loop = setInterval(function () {
var data = { x : i, y : i * (Math.random() * 10) };
var streamObject = JSON.stringify(data);
stream1.write(streamObject+'\n');
i++;
}, 1000);
});