Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load JSON Data on google visualization Chart?

I'm new with google-visualization. I'm developing a full dashboard like google full dashboard example

Following the example I declare data like this:

var data = google.visualization.arrayToDataTable([
    ['CodiceCliente', 'Cliente', 'QtàO13', 'QtàO14','UM'],
        ['0000038893', 'Coop',300,350, 'CT'] .... ]);

Now I want to load data from server. I create a Json like this:

{
"cols": [
    {"id": "codiceCliente","label": "Cod. Cliente","type": "string"},
    {"id": "clienteDesc","label": "Cliente","type": "string"},
    {"id": "qtaO13","label": "Qtà O13","type": "number"},
    {"id": "qtaO14","label": "Qtà O14","type": "number"},
    {"id": "um","label": "UM","type": "string"}
       ],
"rows": [
    {
        "c": [
            {"v": "0000038893"},
            {"v": "Coop"},
            {"v": "300"},
            {"v": "350"},
            {"v": "CT"} ]
        }, 
        {.... }, ... ]}

In html page i use this code to get data from server:

 var jsonData = $.ajax({
      url: "getJson.do",
      dataType:"json",
      async: false
      }).responseText;
  var data = google.visualization.DataTable(jsonData);

When I open the page, I get this error: " Object # has no method 'zg' at format+it,default+it,ui+it,controls+it,corechart+it.I.js:183 "

where am I wrong? JSON format is wrong?

like image 459
Giacomo Savioli Avatar asked Mar 25 '14 11:03

Giacomo Savioli


People also ask

How do I visualize a JSON file?

Use your JSON REST URL to visualize. Click on the Load URL button, Enter URL and Submit. Users can also visualize JSON in graph by uploading the JSON file. JSON Visualizer works well on Windows, MAC, Linux, Chrome, Firefox, Edge, and Safari.

How do I add data to a Google chart?

Double-click the chart you want to change. At the right, click Setup. Select the cells you want to include in your chart. Optional: To add more data to the chart, click Add another range.

How do I use CSV data in a Google chart?

Reading CSV files If you want to build a chart out of CSV (comma-separated values) data, you have two choices: Convert the data into the Google Charts datatable format. Place the CSV file on the web server serving the chart, and query it using the technique on this page.


1 Answers

You are missing the new keyword in the DataTable constructor. It should be:

var data = new google.visualization.DataTable(jsonData);
like image 151
asgallant Avatar answered Oct 14 '22 16:10

asgallant