我实现了谷歌dount图表,现在我尝试使用ajax设置数据。在谷歌中,除了这样的数据之外,不会绘制图表。
['Category', 'Amount'],
['Photos', 22],
['Videos', 9],
['Free Space', 9]
但是当我尝试创建这样的数组时,它会显示不同的格式。
["title", "receiptAmount", "Expense category", "50"]
那么我该怎么做才能转换为上述格式。我尝试了很多方法来转换它,但我没有取得任何成功,我展示了我可以用代码尝试什么。
var arrValues = [];
arrValues = ['title', 'receiptAmount'];
for(var i=0; i<data.length; i++)
{
arrValues.push(data[i]['title'],data[i]['receiptAmount']);
dataArray = arrValues;
}
console.log(dataArray);
请帮我解决这个问题吗?
最佳答案
您需要将
var arrValues = [];
arrValues.push(['title', 'receiptAmount']);
for(var i=0; i<data.length; i++) {
arrValues.push(
[data[i]['title'], data[i]['receiptAmount']]
);
}
console.log(arrValues);
关于javascript - 将数组转换为正确的格式以在 Google 图表中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61171060/