我创建了一个实时使用teechart html5 javascript。一切都很好,第一次。但是当api第二次命中并且在数组中推送数据时我得到一个错误,即“Uncaught TypeError:无法读取未定义的属性'0'” 任何类型的帮助表示赞赏。提前致谢 下面是我的cde:
function loaddata(d_s,d_l){
if(s==0) {
resizeCanvas();
}
abc = [];
customData = [];
console.log("the start and end values are", d_s, d_l);
$.getJSON('http://dgmv1lmgqmyfc.cloudfront.net/eeg/api/?from='+d_s+'&to='+d_l , function(json) {
var data = $.makeArray(json) ;
for (var i =0 ; i < data.length ; i++) {
customData.push([
data[i].c1,
data[i].c2,
data[i].c3,
data[i].c4,
data[i].c5,
data[i].c6,
data[i].c7,
data[i].c8,
data[i].c9,
data[i].c10,
data[i].c11,
data[i].c12,
data[i].c13,
data[i].c14,
data[i].c15,
data[i].c16,
data[i].c17,
data[i].c18,
data[i].c19,
data[i].id
]);
}
abc = customData;
datasize = abc.length;
num = abc[0].length - 1;
for(var i=0; i<datasize; i++)
{
for(var j=0; j<num; j++)
{
abc[i][j]=abc[i][j]+j*margin;
}
}
draw();
});
this.d_start = this.d_start + this.d_length + 1 ;
this.d_length = this.d_length + 2476 ;
}
function draw(){
if (s == 0)
{
Chart1=new Tee.Chart('canvas');
addSeries(1);
Chart1.panel.transparent=true;
Chart1.walls.back.visible=false;
Chart1.legend.visible=false;
Chart1.axes.left.title.text='Data';
Chart1.title.text='';
}
if(on == 0)
Chart1.draw();
if(on == 1)
requestAnimFrame(newData, Chart1, 1);
function newData() {
iCounter++ ;
if(on == 0) return;
for(var t=0; t < num; t++){ // loop run 19 times
var d=Chart1.getSeries(t).data.values;
var x=Chart1.getSeries(t).data.x;
var l=d.length;
var e = document.getElementById('sel_shift');
//console.log("asdsadsad",x);
//exit;
nrshift = e.options[e.selectedIndex].value;
for (v=0; v<nrshift; v++){ // loop run 20 time is 20 selected from dropdown
if((x[l-1]+v)>=d_start){break;} /////////
if(x[l-1]>=d_length){
var cn = x[l-1];
for(;cn > d_length-1;){
cn = cn - d_length;
}
d[l]= abc[cn][t];
if(cn<1){
d[l]=d[l-1];
}
}else{
d[l]= abc[x[l-1]+v][t];
//console.log(abc[x[l-1]+v][t]);
}
x[l]= x[l-1]+1;
d.shift();
x.shift();
}
//console.log("the updated countrer is", iCounter);
}
Chart1.draw();
if((x[l-1])>=d_start){
//this.d_start = this.d_start + this.d_length ;
loaddata(d_start,d_length);
}else{
requestAnimFrame(newData,Chart1,1);
}
}
} //在此处关闭绘制方法