gpt4 book ai didi

javascript - addListener 事件——错误

转载 作者:行者123 更新时间:2023-12-03 12:35:15 49 4
gpt4 key购买 nike

我正在尝试在行和数据点之间构建一个事件处理程序。我当前收到错误:

TypeError: line.getSelection is not a function.

我不太确定如何添加此功能或者我可能会出错的地方:

        var table = new google.visualization.ChartWrapper({
'chartType': 'Table',
'containerId': 'TableContainer',
'options': { 'height': '25em', 'width': '80em' }
});

new google.visualization.Dashboard(document.getElementById('PieChartExample')).bind([myIdSlider], [line, table]).draw(data);
table.draw(data, { showRowNumber: true });

google.visualization.events.addListener(line, 'select', function () {
table.setSelection([{ row: line.getSelection()[0].row }]);
});

google.visualization.events.addListener(table, 'select', function () {
line.setSelection(table.getSelection());
});

// table.setSelection([{ row: chart.getSelection()[0].row }]);


}

任何帮助将不胜感激。非常感谢。

最佳答案

假设您的 line 变量是 ChartWrapper(如 table),您需要使用:

google.visualization.events.addListener(line, 'select', function () {
var lineSelection = line.getChart().getSelection();
var tableSelection = [];
for (var i = 0; i < lineSelection.length; i++) {
// iterate over lineSelection, since it could potentially contain multiple or 0 elements
// check to see if "row" property is defined, since clicking on the legend fires a select event with no "row" property
if (lineSelection[i].row != null) {
tableSelection.push({row: lineSelection[i].row});
}
}
table.getChart().setSelection(tableSelection);
});

google.visualization.events.addListener(table, 'select', function () {
var tableSelection = table.getChart().getSelection();
var lineSelection = [];
for (var i = 0; i < lineSelection.length; i++) {
// iterate over lineSelection, since it could potentially contain multiple or 0 elements
lineSelection.push({
row: tableSelection[i].row,
column: /* choose a column to select */
});
// you may add more selections here if you want to select points from multiple data series
}
line.getChart().setSelection(lineSelection);
});

关于javascript - addListener 事件——错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23764743/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com