我的折线图一直收到以下错误 - 几天前工作正常,但现在我收到以下错误...
错误:类型不匹配。值0与列索引1中的类型编号不匹配 我的图表代码如下......
这表明我添加到第一列的移位值不会被识别为数字,但我不明白为什么?
drawDisplacementChart(xml, markers){
//array to hold data
var graph = [];
//data table object
var dataTable = new google.visualization.DataTable();
//chart options
var options = {title:'Displacement (m)/Time (minutes)',
legend:{position:'bottom'},
is3d:true
};
//get first point of route- displacement is distance travelled away from this point
var startPoint = new google.maps.LatLng(markers[0].getAttribute("lat"),markers[0].getAttribute("lng"));
//loop through xml
for(var i = 0; i<markers.length; i++){
//var to represent time - reading being taken every minute
var time = i+':00';
//find the current position in route
var current = new google.maps.LatLng(markers[i].getAttribute("lat"),markers[i].getAttribute("lng"));
//calculate displacement
var displacement = google.maps.geometry.spherical.computeDistanceBetween(startPoint,current);
console.log(displacement);
//store values in array
graph[i] = [time, displacement];
}
//instantiates chart object
var chart = new google.visualization.LineChart(document.getElementById('chart_div2'));
//set columns in data table
dataTable.addColumn('string', 'time');
dataTable.addColumn('number', 'Displacement');
var array = [];
//loop through stored values
for(var i = 0; i<graph.length; i++){
//timeout to allow periodic addition
setTimeout(function(y){
array.push(graph[y]);
dataTable.addRows(array);
//add value to chart
chart.draw(dataTable, options);
//empty array for next iteration
array = [];
}, i*TIME, i);
}
}