Not beeing able to read data from JSON

29 views
Skip to first unread message

bernat sopena

unread,
Sep 14, 2017, 11:43:56 AM9/14/17
to Google Visualization API
I have queried data from an external source using python, created a DataTable using the library using gviz_api and then transformed into json by using the .ToJSon method, problem is that when trying to create a graph out of this the error "This table has no columns" keeps rising.

Here is the rellevant part of my script.



schema
= [('id2',), ('id3',), ('id1',)]
data_gviz
=[['556', '556', '556\n']]


#Load into a gv.DataTable
data_table
= gv.DataTable(schema)
data_table
.LoadData(data_gviz)
# Create a JSON string.
json_data
= data_table.ToJSon()

return json_data

-----------------------

<script type="text/javascript">
   
// Load the Visualization API and the scatterplot package.
    google
.charts.load('current', {'packages':['corechart']});
   
// Set a callback to run when the Google Visualization API is loaded.
    google
.charts.setOnLoadCallback(drawChart);
   
function drawChart() {
     
var jsonData = $.ajax({
          url
: "getData.py",
          dataType
: "json",
          async
: false
         
}).responseText;
     
// 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.PieChart(document.getElementById('chart_hbase'));
      chart
.draw(data, {width: 400, height: 240});
   
}



 
</script>

This error keeps appearing:

Also I have tried to run as it is this example: https://developers.google.com/chart/interactive/docs/php_example

and it doesnt seem to be working.

Any help is much appreciated.



Reply all
Reply to author
Forward
0 new messages