谷歌图表 - 地理图表“不兼容的数据表:错误:未知地址类型

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

本文关键字:错误 未知 类型 数据表 地址 不兼容 谷歌      更新时间:2023-09-26

我正在尝试使用从mysql检索并在PHP中解析的一组数据来生成GeoChart。但是,我很确定错误出在我的JavaScript上。我简化了数据,使其更易于理解。

这是我的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);
}

在页面中,我只得到红色文本,上面写着:

Incompatible data table: Error: Unknown address type.

我有其他图表使用具有相同格式/布局的数据表工作正常。

任何帮助表示赞赏,

干杯

我修复了它。我只需要指定column的类型是string还是number

例:

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