当我使用这行代码时:
for (var j = 0; j < data_ram.length; ++j) {res_ram.push([j, data_ram[j]]);}
res_cpu 根本没有返回好的数据。它支持返回一个空数组(长度为 30)。
这是返回值:
这是我的完整代码:
var data_cpu = [];
var data_ram = [];
var totalPoints = 30;
// random data generator for plot charts
function getRandomData() {
if (data_cpu.length > 0 && data_ram.length > 0) {
data_cpu = data_cpu.slice(1);
data_ram = data_ram.slice(1);
data_cpu.push(50);
data_ram.push(50);
var res_ram = [];
var res_cpu = [];
for (var i = 0; i < data_ram.length; ++i) res_ram.push([i, data_ram[i]])
for (var i = 0; i < data_cpu.length; ++i) res_cpu.push([i, data_cpu[i]])
return [res_cpu, res_ram];
}else {
while (data_ram.length < totalPoints) {
data_ram.push(null);
}
while (data_cpu.length < totalPoints) {
data_cpu.push(null);
}
var res_cpu = [];
var res_ram = [];
for (var i = 0; i < data_cpu.length; ++i) {res_cpu.push([i, data_cpu[i]]);}
for (var j = 0; j < data_ram.length; ++j) {res_ram.push([j, data_ram[j]]);}
alert(res_cpu);
return [res_cpu,res_ram];
}
}