2014-05-20 22 views
0

我想在行和數據點之間建立一個事件處理程序。我目前得到一個錯誤:addListener事件 - 錯誤

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 }]); 


    } 

任何幫助將是非常讚賞。非常感謝。

+2

我看不到的地方行變量聲明。 – Ksv3n

+0

沒有行聲明。但是,請嘗試window.getSelection() –

+0

謝謝大家的迴應。我嘗試添加「窗口」行,但它輸出的錯誤響應與'line.window'未定義一樣。我也得到另一個警告錯誤 - 空字符串傳遞給getElementById()。我相信這個警告與錯誤有關,因爲無論我何時點擊表格行,它都會增加計數。請指教。謝謝 – user3070072

回答

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); 
}); 
+0

這非常有幫助。我非常感謝你的幫助,時間和辛勤的工作,使這個解釋/解決方案。非常感謝= D – user3070072