63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
/* If you have not signed up for Plotly you can do so using https://plot.ly
|
|
* or see the example signup.js. Once you do, populate the config.json in this
|
|
* example folder!
|
|
*/
|
|
var config = require('./config.json')
|
|
, username = config['user']
|
|
, apikey = config['apikey']
|
|
, token = config['token']
|
|
, Plotly = require('../.')(username, apikey)
|
|
, Signal = require('random-signal')
|
|
|
|
|
|
// build a data object - see https://plot.ly/api/rest/docs for information
|
|
var data = {
|
|
'x':[] // empty arrays since we will be streaming our data to into these arrays
|
|
, 'y':[]
|
|
, 'type':'scatter'
|
|
, 'mode':'lines+markers'
|
|
, marker: {
|
|
color: "rgba(31, 119, 180, 0.96)"
|
|
}
|
|
, line: {
|
|
color:"rgba(31, 119, 180, 0.31)"
|
|
}
|
|
, stream: {
|
|
"token": token
|
|
, "maxpoints": 100
|
|
}
|
|
}
|
|
|
|
// build you layout and file options
|
|
var layout = {
|
|
"filename": "streamSimpleSensor"
|
|
, "fileopt": "overwrite"
|
|
, "layout": {
|
|
"title": "streaming mock sensor data"
|
|
}
|
|
, "world_readable": true
|
|
}
|
|
|
|
/*
|
|
* Call plotly.plot to set the file up.
|
|
* If you have included a streaming token
|
|
* you should get a "All Streams Go!" message
|
|
*/
|
|
|
|
Plotly.plot(data, layout, function (err, resp) {
|
|
if (err) return console.log("ERROR", err)
|
|
|
|
console.log(resp)
|
|
|
|
var plotlystream = Plotly.stream(token, function () {})
|
|
var signalstream = Signal({tdelta: 100})
|
|
|
|
|
|
plotlystream.on("error", function (err) {
|
|
signalstream.destroy()
|
|
})
|
|
|
|
// Okay - stream to our plot!
|
|
signalstream.pipe(plotlystream)
|
|
})
|