javascript - 谷歌图表 - GeoChart "Incompatible data table: Error: Unknown address type."

标签 javascript json google-visualization

我正在尝试使用一组从 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'}
],

关于javascript - 谷歌图表 - GeoChart "Incompatible data table: Error: Unknown address type.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12004074/

相关文章:

javascript - 处理 Javascript 中的嵌套 Interval

javascript - 更新 fabric.Path 中的选择框

javascript - 进入对象或对象的对象的条目和键

php - 如何遍历嵌套的 stdClass?

charts - 用于显示最小值/最大值/平均值的条形图

javascript - 将堆积柱形谷歌图表转换为瀑布图

javascript - google.setOnLoadCallback() 不适用于单独的 JS 文件

php - 使用 CSV 文件的 JavaScript 和 JQuery 多维数组搜索

javascript - 如何仅更新 javascript 中二维数组的给定索引?

jquery - jsTree 未使用 "inline"json 数据进行渲染