我一直试图用flotjs实时绘制图形。外部数据来自arduino。我的问题是得到这个错误:未捕获的typeerror undefined不是函数 < / p>
var socket = io.connect('http://localhost:8000');
socket.on('pulse', function(data){
var datas = [],
totalPoints = 300;
function getData() {
if (datas.length > 0)
datas = datas.slice(1);
// Do a random walk
while (datas.length < totalPoints) {
datas.push(data);
}
// Zip the generated y values with the x values
var res = [];
for (var i = 0; i < datas.length; ++i) {
res.push([i, datas[i]]);
}
return res;
}
var plot = $.plot("#placeholder", [ getData() ], {
series: {
shadowSize: 0 // Drawing is faster without shadows
},
yaxis: {
min: 0,
max: 100
},
xaxis: {
show: false
}
});
function update() {
plot.setData([getData()]);
// Since the axes don't change, we don't need to call plot.setupGrid()
plot.draw();
setTimeout(update, updateInterval);
}
update();
错误发生在这一行:
var plot = $.plot("#placeholder", [ getData() ], {
...
有什么问题?
答案 0 :(得分:2)
我解决了。它不仅仅是提供静态文件。