0
您可以使用節點js下載整個模塊。現在,我通過使用我的API密鑰來使用節點js來繪製數據。如果有辦法,可以一步一步地指導嗎?我試過https://www.npmjs.com/package/plotly.js,但它不起作用。下載節點js上的開放源代碼
var plotly = require('plotly.js');
var initdata = [{x:[], y:[], stream:{token:'t2166m92ft', maxpoints:50}}];
var initlayout = {fileopt : 'overwrite', filename : 'nodenodenode5'};
plotly.plot(initdata, initlayout, function (err, msg) {
if (err) return console.log(err);
console.log(msg);
var stream1 = plotly.stream('t2166m92ft', 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() {
client.once('message', function (message) {
var data = { x : i , y : message.toString()};
var streamObject = JSON.stringify(data);
stream1.write(streamObject+'\n');
i++;
});
}, 5000);
});
}
當我試圖使用NPM安裝plotly.js安裝,跑到我的節目我:
\Users\intern\Documents\universal-ground-system\Node js\node_modules\plotly.js
rc\lib\index.js:397
var style = document.createElement('style');
^
ReferenceError: document is not defined
at Object.lib.addStyleRule (C:\Users\intern\Documents\universal-ground-syste
Node js\node_modules\plotly.js\src\lib\index.js:397:21)
at Object.<anonymous> (C:\Users\intern\Documents\universal-ground-system\Nod
js\node_modules\plotly.js\build\plotcss.js:61:16)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (C:\Users\intern\Documents\universal-ground-system\Nod
js\node_modules\plotly.js\src\plotly.js:30:1)
at Module._compile (module.js:409:26)