javascript - Google 图表选择事件中未定义列索引

标签 javascript google-visualization

我在 Google 图表中的选择事件中得到了未定义的列索引。还有类似问题here , here ,和here我看过了,但没有解决我的问题。我的目标是能够确定用户何时单击“[ x ]”以从表中删除相应的行。谢谢。

var data = new google.visualization.DataTable();
data.addColumn('string', 'Site');
data.addColumn('number', 'Logins');
data.addColumn('string', '');
data.addRows([['ABC', 123, '[ x ]']]);

function drawTable() {
    // Create and draw the visualization.
    visualization = new google.visualization.Table(document.getElementById('table_div'));
    visualization.draw(data, null);
    google.visualization.events.addListener(visualization, 'select', selectHandler);
}

function selectHandler() {
    var selectedItem = visualization.getSelection()[0];
    console.log(selectedItem); // output:  Object {row: 0} 

    if (selectedItem == undefined)
        return false;

    console.log(selectedItem.column); // output: undefined

    var value = data.getValue(selectedItem.row, selectedItem.column);
    console.log(value); // output: Uncaught Error: Invalid column index undefined. Should be an integer in the range [0-3].
}

最佳答案

看起来表格图表仅返回具有选择事件的行,因为表格可视化是为选择行而设计的。我在 Google Visualization API Group 找到了这个

这是documentation说明表格图表只能选择行。

关于javascript - Google 图表选择事件中未定义列索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13887503/

相关文章:

javascript - 在不复制的情况下通过 WebSocket 发送 ArrayBuffer 的子段

javascript - 在 Bower 中使用 URL 文件名而不是 index.js

javascript - 如何设置注释文本或值的方向

javascript - 谷歌图表 : Point with border

javascript - 在 html 中修复 Google 表格标题

javascript - 谷歌图表在多个时不起作用

用于扩展导航栏的 Javascript 代码无法按预期工作

php - PHP 中的 Javascript 变量

JavaScript:控制台中显示的原型(prototype)函数

javascript - 如何在谷歌柱形图 api 中添加链接(可点击并获取新数据)