The object does not have a getColumnType error method

I read the solution on this , but does not seem to be suitable for my problem. I use google charts to build a line chart. the x axis is a date, and the y axis is an integer.

When I run my code, I get a big error message

The object {"it then lists all my formatted JSON data"} does not have a getColumnType method.

I get JSON chart data from a web service through an AJAX call. My code is bye

<script type="text/javascript"> google.load("visualization", "1", { packages: ["corechart"] }); google.setOnLoadCallback(drawChart); function drawChart() { var jsonData = $.ajax({ url: "WebService.asmx/HelloWorld", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", async: false }).responseText; var options = { title: 'Company Performance' }; var chart = new google.visualization.LineChart(document.getElementById('chart_div1')); chart.draw(jsonData, options); } </script> 
+4
source share
2 answers

The solution is simple ... You cannot fill a google diagram directly from JSON data. JSON must first be formatted as data. The solution looks like this:

  // Load the Visualization API and the piechart package. google.load('visualization', '1', { 'packages': ['annotatedtimeline'] }); // Set a callback to run when the Google Visualization API is loaded. google.setOnLoadCallback(drawChart); function drawChart() { var jsonData = $.ajax({ url: "JSON.txt", dataType: "json", async: false }).responseText; // HERE IS THE FIX!!! Create our data table out of JSON data loaded from server. var data = new google.visualization.DataTable(jsonData); // Instantiate and draw our chart, passing in some options. var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div1')); chart.draw(data, { width: 400, height: 240 }); } 
+3
source

I think you need to explicitly parse JSON; $.ajax() will not do this for you in this case.

Try adding:

  jsonData = JSON.parse(jsonData); 

before creating a chart.

Now, I said, I don’t know what it is that is looking for the getColumnType() function; which will not be present in your JSON response as a string or collapsible form.

0
source

Source: https://habr.com/ru/post/1446384/


All Articles