我想创建一个像下面这样的二维数组
var seriesArray = [{
name: 'Year 1800',
data: [107, 31, 635, 203, 2]
}, {
name: 'Year 1900',
data: [133, 156, 947, 408, 6]
}, {
name: 'Year 2000',
data: [814, 841, 3714, 727, 31]
}, {
name: 'Year 2016',
data: [1216, 1001, 4436, 738, 40]
}];
查看示例Click Here
我正在做什么来创建这样的数组
var continents = ['Africa', 'America', 'Asia', 'Europe', 'Oceania']
var years = [1800, 1900, 2000, 2016];
for (var i = 0; i < years.length; i++) {
var data = [];
for (var j = 0; j < continents.length; j++) {
data.push(10);
}
seriesArray.push([years[i], data]);
}
图表上没有显示任何内容。我正在创建阵列吗?还有其他方法吗?
Here the screenshot of seriesArray数据,我认为我的数组不是关联数组,有谁能告诉我该怎么做?
答案 0 :(得分:0)
你错了你的循环。你必须像这样构建你的行:
var continents = ['Africa', 'America', 'Asia', 'Europe', 'Oceania']
var years = [1800, 1900, 2000, 2016];
for (var i = 0; i < continents.length; i++) {
var data = [];
for (var j = 0; j < years.length; j++) {
data.push(10);
}
var row={};
row['year']=years[i];
row['data']=data;
seriesArray.push(row);
}
希望有所帮助