How to dynamically add rows/columns to a Google Column Chart

后端 未结 3 989
旧时难觅i
旧时难觅i 2021-01-31 00:27

I want to create a Column Chart , using Google Visualization API , I can send the data to populate the chart\'s DataTable in array form. But I need to generate the chart with va

3条回答
  •  再見小時候
    2021-01-31 00:57

    You can put the data in one string and use JSON.parse(stringData). The year column must be in double quotes

    var data = new google.visualization.DataTable();  
    data.addColumn('string', 'Year');  
    data.addColumn('number', 'Sales'); 
    data.addColumn('number', 'Expenses'); 
    
    var stringData = '[["2004", 1000 , 400], ["2005", 1170, 460], ["2006", 660, 1120], ["2007",1030,540]]';
    
    data.addRows(JSON.parse(stringData));
    

提交回复
热议问题