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