我有一個(gè)從 mysql 數(shù)據(jù)庫(kù)中提取數(shù)據(jù)的谷歌圖表。如果我將返回的數(shù)組 (arr) 直接傳遞給 DataTable(),它會(huì)起作用: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);現(xiàn)在我想在分配數(shù)組之前添加一些列。這會(huì)導(dǎo)致錯(cuò)誤。我用谷歌搜索了很多例子(例如這個(gè),但找不到我做錯(cuò)了什么。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);
將列分配給 Google 圖表
慕后森
2023-07-06 18:23:09