UNPKG

789 BJavaScriptView Raw
1'use strict';
2
3var plotly = require('../.')('plotlyUsername','apiKey');
4
5var initdata = [{x:[], y:[], stream:{token:'streamToken', maxpoints:200}}];
6var initlayout = {fileopt : 'overwrite', filename : 'nodenodenode'};
7
8plotly.plot(initdata, initlayout, function (err, msg) {
9 if (err) return console.log(err);
10 console.log(msg);
11
12 var stream1 = plotly.stream('streamToken', function (err, res) {
13 if (err) return console.log(err);
14 console.log(res);
15 clearInterval(loop); // once stream is closed, stop writing
16 });
17
18 var i = 0;
19 var loop = setInterval(function () {
20 var data = { x : i, y : i * (Math.random() * 10) };
21 var streamObject = JSON.stringify(data);
22 stream1.write(streamObject+'\n');
23 i++;
24 }, 1000);
25});
26