I am fetching data table from google sheet, but Pie chart is unable to read the Array. I am getting below error on console.
Uncaught Error: Unknown type of column header: 1
I am using below script to get the data from Google Spreadsheet.
Code.gs:
function vodPiechart() {
const ss = SpreadsheetApp.openById("");
const sw = ss.getSheetByName("Pie_Chart_Data");
var data = sw.getRange (1,1,3, 2).getValues();
return data
}
HTML Script (from Google Charts)
<script type="text/javascript">
google.charts.load("current", {packages:["corechart"]});
google.charts.setOnLoadCallback(getData);
function getData(){
google.script.run.withSuccessHandler(drawChart).vodPiechart();
}
function drawChart(dataReturened) {
var data = google.visualization.arrayToDataTable(dataReturened);
console.log(dataReturened);
var options = {
title: 'My Channel',
is3D: true,
};
var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
chart.draw(data, options);
}
</script>
console.log of dataReturned:
Array(3) [ (2) […], (2) […], (2) […] ]
0: Array [ "Task", "Views" ]
1: Array [ "Channel A", 2854170 ]
2: Array [ "CHannel B", 240222 ]
length: 3
<prototype>: Array []
Could anyone please tell me, what I am doing wrong here?
THANK YOU