如何在 google table 图表中使用 javascript 数组?
how can I use javascript array in google table chart?
我有一个 javascript 数组,如何为 google table 图表输入行? (google 图表可视化)
我试图将它自己作为数组插入,但它不起作用。
en <script type="text/javascript"
src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
var myarr = new Array();
myarr = JSON.parse(localStorage.getItem("arr"));
google.charts.load('current', {'packages':['table']});
google.charts.setOnLoadCallback(drawTable);
data.addColumn('string', 'Zipcode');
data.addColumn('string', 'City');
data.addColumn('String', 'State');
//arr[0][0] to arr[0][arr[0].length] is column name
data.addRows([
//I don't know how to work here with array
var table = new google.visualization.Table(document.getElementById('table_div'));
table.draw(data, {showRowNumber: true, width: '100%',
height: '100%'});*/
</script>
数组是二维数组。
例子
example array
如果你所有的数据都在数组中,那么你可以使用方法 --> arrayToDataTable
var myarr = new Array();
myarr = JSON.parse(localStorage.getItem("arr"));
var data = google.visualization.arrayToDataTable(myarr);
我有一个 javascript 数组,如何为 google table 图表输入行? (google 图表可视化)
我试图将它自己作为数组插入,但它不起作用。
en <script type="text/javascript"
src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
var myarr = new Array();
myarr = JSON.parse(localStorage.getItem("arr"));
google.charts.load('current', {'packages':['table']});
google.charts.setOnLoadCallback(drawTable);
data.addColumn('string', 'Zipcode');
data.addColumn('string', 'City');
data.addColumn('String', 'State');
//arr[0][0] to arr[0][arr[0].length] is column name
data.addRows([
//I don't know how to work here with array
var table = new google.visualization.Table(document.getElementById('table_div'));
table.draw(data, {showRowNumber: true, width: '100%',
height: '100%'});*/
</script>
数组是二维数组。 例子 example array
如果你所有的数据都在数组中,那么你可以使用方法 --> arrayToDataTable
var myarr = new Array();
myarr = JSON.parse(localStorage.getItem("arr"));
var data = google.visualization.arrayToDataTable(myarr);