我正在尝试在行和数据点之间构建一个事件处理程序。我目前收到错误:
TypeError:line.getSelection不是函数。
我不确定,如何添加此功能或我可能出错的地方:
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 }]);
}
非常感谢任何帮助。非常感谢。
答案 0 :(得分:1)
假设您的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);
});