简体   繁体   中英

Google Chart Error - Data table has no columns

I'm pulling some data from a server and it seems correctly formatted - but I cant seem to get the google chart object to recognise the columns.

The code is generated from a large table - but even reducing the number of rows and columns to just a small test set, I keep getting the error.

data is being grabbed using jQuery and defined for the chart as follows:

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

Can anyone notice my error?

Thanks!

{
  cols: [
              {id:"2",label:"ADL",type:"string"},
              {id:"3",label:"TOT",type:"number"},
              {id:"10",label:"CON",type:"number"},
              {id:"11",label:"SLS",type:"number"}
      ],
  rows: [
           {c:[
                    {v:"[FASHION/FINE/METAL/PREVIEW-ALL][20190517-20190615]"},
                    {v:19},
                    {v:0},
                    {v:0.0000}
                  ]
           },
           {c:[
                    {v:"Intensive Landing: Fashion"},
                    {v:7},
                    {v:0},
                    {v:0.0000}
                  ]
           },
           {c:[
                    {v:"Intensive Landing: Fine"},
                    {v:1},
                    {v:0},
                    {v:0.0000}
                  ]
           },
           {c:[
                    {v:"Internet: Google"},
                    {v:1},
                    {v:0},
                    {v:0.0000}
                  ]
           },
           {c:[
                    {v:"Internet: CHAT"},
                    {v:3},
                    {v:0},
                    {v:0.0000}
                  ]
           },
           {c:[
                    {v:"Internet: Query"},
                    {v:1},
                    {v:0},
                    {v:0.0000}
                  ]
           },
           {c:[
                    {v:"Referral: Saiman"},
                    {v:1},
                    {v:0},
                    {v:0.0000}
                  ]
           }
      ]
}

Here's a working fiddle using your data: https://jsfiddle.net/f9sz2nmx/1

dataTable = new google.visualization.DataTable(jsonData);
options = { /* options */ };
chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(dataTable, options);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM