Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

319
Views
Unable to read Data Array. Getting: Uncaught Error: Unknown type of column header: 1

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

something about the data is incorrect.

the error message you received is thrown when column headings do not exist in the data.
or the value of the column heading is not a string.

Uncaught Error: Unknown type of column header: 1

in this case, the number 1 is trying to be used as a column heading.

see following example, the following error will be thrown.

Uncaught Error: Unknown type of column header: 2854170

google.charts.load('current', {
  packages:['corechart']
}).then(function () {
  var data = google.visualization.arrayToDataTable([
    ["Channel A", 2854170],
    ["Channel B", 240222],
  ]);

  var options = {
    title: 'My Channel',
    is3D: true,
  };

  var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
  chart.draw(data, options);
});

the arrayToDataTable method has a second, boolean argument.
when set to true, it will create the data table without column headings,
and use the first row as data.

var data = google.visualization.arrayToDataTable([
  ["Channel A", 2854170],
  ["Channel B", 240222],
], true);  // <-- first row is data

there are really no use for column headings in a pie chart,
because the labels are provided on each row.

try adding the boolean argument for resolution.

see following working snippet...

google.charts.load('current', {
  packages:['corechart']
}).then(function () {
  var data = google.visualization.arrayToDataTable([
    ["Channel A", 2854170],
    ["Channel B", 240222],
  ], true);

  var options = {
    title: 'My Channel',
    is3D: true,
  };

  var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
  chart.draw(data, options);
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="piechart_3d"></div>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!