gpt4 book ai didi

javascript - 动态添加行到任何 Google.Visualization

转载 作者:行者123 更新时间:2023-12-03 08:19:14 25 4
gpt4 key购买 nike

我有一个包含 5 个对象的 accounts 数组

我想循环访问这些对象,并向我的 ColumnChart Google 图表添加行/列。我试过了,但没有看到任何效果

<script>

google.load('visualization', '1', {packages: ['corechart', 'bar']});
google.setOnLoadCallback(drawMultSeries);

function drawMultSeries() {

var data = google.visualization.arrayToDataTable([
['max_up', 'cpe_mac_up', 'cpe_guaranty_up', 'cpe_guaranty_down', 'cpe_mac_down','max_down', { role: 'annotation' } ],
['1000', 10, 24, 20, 32, 18, ''],
['10001', 16, 22, 23, 30, 16,233],
['1002', 28, 19, 29, 30, 12,'']
]);

//I'm trying to make a loop here
for (var i = 0; i < accounts.length; i++) {
//console.log(accounts[i].account_id);
data.addRow[accounts[i].account_id, 28, 19, 29, 30, 12,'']

}

var options = {
width: 600,
height: 400,
legend: { position: 'top', maxLines: 3 },
bar: { groupWidth: '15%' },
isStacked: true,
};

var chart = new google.visualization.ColumnChart(
document.getElementById('chart_div'));

chart.draw(data, options);
}

</script>

_
<小时/>

结果

enter image description here

<小时/>

对此的任何提示/建议将不胜感激!

<小时/>

更新

感谢 Simon 发现了这一行的错误

data.addRow(['accounts[i].account_id', 28, 19, 29, 30, 12,'']);

现在我的图表看起来像这样

enter image description here

没有显示任何内容

最佳答案

您的线路:

data.addRow[accounts[i].account_id, 28, 19, 29, 30, 12,'']

需要:

data.addRow([accounts[i].account_id.toString(), 28, 19, 29, 30, 12,'']);

根据评论:)

关于javascript - 动态添加行到任何 Google.Visualization,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33804142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com