简体   繁体   中英

Google Chart - GeoChart “Incompatible data table: Error: Unknown address type.”

I'm trying to generate a GeoChart using a set of data retrieved from mysql and parsed in PHP. However, I'm pretty sure that the error lies in my JavaScript. I've simplified the data to make it easier to understand.

Here is my JavaScript:

// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['geochart']});

// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);

// Callback that creates and populates a data table,
// instantiates the geo chart, passes in the data and
// draws it.

function drawChart() {

// Create the data table.
var data = new google.visualization.DataTable(
{
    cols: [
      {id: '0', label: 'Country'},
      {id: '1', label: 'Downloads'}
     ],
    rows: [
      {c:[{v: 'GB'}, {v: 166020}]}
     ]      
 }
);

// Set chart options
var options = {
    title:'Downloads in Last 30 Days',
    width:900,
    height:700,                 
};

// Create and draw the visualization.
visualization = new google.visualization.GeoChart(document.getElementById('chart_div1'));
visualization.draw(data, options);

}

In the page I just get red text that says:

Incompatible data table: Error: Unknown address type.

I have other charts working fine using a datatable with the same format/layout.

Any help appreciated,

Cheers

I fixed it. I just needed to specify the type of column was a string or a number .

Example:

cols: [
  {id: '0', label: 'Country', type: 'string'},
  {id: '1', label: 'Downloads', type: 'number'}
],

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