我有一个从 mysql 数据库中提取数据的谷歌图表。如果我将返回的数组 (arr) 直接传递给 DataTable(),它会起作用:var container = document.getElementById('chart_div');var chart = new google.visualization.Timeline(container);var dataTable = new google.visualization.DataTable(arr);var options = {}; // assign some optionschart.draw(dataTable, options);现在我想在分配数组之前添加一些列。这会导致错误。我用谷歌搜索了很多例子(例如这个,但找不到我做错了什么。var container = document.getElementById('chart_div');var chart = new google.visualization.Timeline(container); var dataTable = new google.visualization.DataTable(); dataTable.addColumn({ type: 'string', id: 'Name' });dataTable.addColumn({ type: 'date', id: 'Start' });dataTable.addColumn({ type: 'date', id: 'End' }); // Uncaught (in promise) Error: Argument given to addRows must be either a number or an arrayvar rows = JSON.parse(arr);dataTable.addRows(rows);// This doesn't work either: Uncaught (in promise) Error: Argument given to addRows must be either a number or an arraydataTable.addRows(arr);var options = {}; // assign some optionschart.draw(dataTable, options);
添加回答
举报
0/150
提交
取消