我需要一些Google API数据阵列创建方面的帮助。请参阅以下详细信息: 我有以下数组,我正在动态创建。
schoolYear = [ 2014,2015,];
schoolReading = [420.5,520.5,];
schoolWriting = [436.5,536.5,];
schoolSpelling = [425.1,525.1,];
schoolNumeracy = [395.5,495.5,];
schoolGramPunc = [436,536,];
schoolTotAvg = [437,537,];
我正在尝试像这样创建google.visualization.arrayToDataTable:
for (i = 0; i < schoolTotAvg.length; i++) {
var data = google.visualization.arrayToDataTable([
['Year', 'Reading', 'Numeracy', 'Grammar/Punctuation', 'Writing', 'Spelling', 'Total Average'],
[schoolYear, schoolReading, schoolNumeracy, schoolGramPunc, schoolWriting, schoolSpelling, schoolTotAvg]
]);
}
当我看到页面源时,我没有得到正确的数组。
有人可以帮忙吗?
- 的Pankaj
答案 0 :(得分:4)
我找到了解决方案: - )
var dataArray = [['Year', 'Reading', 'Numeracy', 'Grammar/Punctuation', 'Writing', 'Spelling', 'Total Average']];
for (var n = 0; n < schoolTotAvg.length; n++) {
dataArray.push([schoolYear[n], schoolReading[n], schoolNumeracy[n], schoolGramPunc[n], schoolWriting[n], schoolSpelling[n], schoolTotAvg[n]]);
}
var data = new google.visualization.arrayToDataTable(dataArray);
var options = {
title: 'School Performance',
curveType: 'function',
legend: { position: 'bottom' }
};
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);