Error to the popular Google Chart

Asked

Viewed 131 times

0

The following error appears

Invalid data table format: column #0 must be of type 'string'.

Right now I have the return in json this way:

[{"Field":"OrderTask","Old":"1","New":"2","Modified":"2016-12-08 11:16:27"},
{"Field":"Status","Old":"1","New":"4","Modified":"2016-12-08 13:43:51"}]

And I have the following Google Chart code:

$("#dataTables-tasks tbody").on("click", "tr", function(){

    var idTask = $(this).find('td.id-task').html();
    google.charts.load('current', {'packages':['gantt']});
    google.charts.setOnLoadCallback(drawChart);


     function drawChart() {
       var jsonData = $.ajax({
       url: "../connect/post/select.php",
       dataType: "json",
       data:'numIdTask='+idTask
     }).responseText;

      var data = new google.visualization.DataTable(jsonData);

      var options = {
        width: 550,
        height: 400,
        gantt: {
          trackHeight: 30
        }
      };

      var chart = new google.visualization.Gantt(document.getElementById('chart_div'));

      chart.draw(data, options);
    }
});
  • You have not set the type of each column of your JSON, you have to set before passing the data to the Datatable. See here in the API of Google Charts

  • Take a look at this method as well: https://developers.google.com/chart/interactive/docs/reference?csw=1#Datatable_tojson

  • Worse than I defined, I took after following this part[Populating Data Using Server-Side Code][1] [1]: https://developers.google.com/chart/interactive/docs/php_example#getdataphp-file

  • In your JSON that is coming from the server, is it defined in this format that you sent this link? Check if there is a key calling for type. For that is what the error is reporting.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.