我有一个从 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 options
chart.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 array
var 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 array
dataTable.addRows(arr);
var options = {}; // assign some options
chart.draw(dataTable, options);
万千封印
相关分类