Andrew Gallant, thanks for the reply. Yet selection[0].row is returning undefined. Below is a complete example of the behavior that line of code. My goal is to get the selected element in the timeline, but I'm not having success.
<html> <head> <script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization', 'version':'1','packages':['timeline']}]}"> </script> <script type="text/javascript"> google.setOnLoadCallback(drawChart); function drawChart() { var container = document.getElementById('example1'); var chart = new google.visualization.Timeline(container); var dataTable = new google.visualization.DataTable(); dataTable.addColumn({ type: 'string', id: 'President' }); dataTable.addColumn({ type: 'date', id: 'Start' }); dataTable.addColumn({ type: 'date', id: 'End' }); dataTable.addRows([ [ 'Washington', new Date(1789, 3, 29), new Date(1797, 2, 3) ], [ 'Adams', new Date(1797, 2, 3), new Date(1801, 2, 3) ], [ 'Jefferson', new Date(1801, 2, 3), new Date(1809, 2, 3) ]]); chart.draw(dataTable); google.visualization.events.addListener(chart, 'select', function(){ var selection = chart.getSelection(); if (selection.length) { alert("Row: "+selection[0].row); alert("Length: "+selection.length); }else{ alert("2 - Length: "+selection.length); } }); } </script> </head> <body> <div id="example1" style="width: 900px; height: 180px;"></div> </body> </html> Em quarta-feira, 18 de junho de 2014 15h52min14s UTC-3, JProject escreveu: > > Hello, I want to capture the selected element in my timeline, but > chart.getSelection () [0]. Returns undefined. > > var container = document.getElementById('timeline'); > chartTimeLine = new google.visualization.Timeline(container); > dataTimeLine = new google.visualization.DataTable(); > dataTimeLine.addColumn({ type: 'string', id: 'President' }); > dataTimeLine.addColumn({ type: 'date', id: 'Start' }); > dataTimeLine.addColumn({ type: 'date', id: 'End' }); > > dataTimeLine.addRows([ > [ 'Washington', new Date(1789, 3, 29), new Date(1797, 2, 3) ], > [ 'Jefferson', new Date(1801, 2, 3), new Date(1809, 2, 3) ]]); > chartTimeLine.draw(dataTimeLine); > google.visualization.events.addListener(chartTimeLine, 'select', > timeLineSelected); > > function timeLineSelected(){ > alert(chartTimeLine.getSelection()[0].row); > } > -- You received this message because you are subscribed to the Google Groups "Google Visualization API" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-visualization-api. For more options, visit https://groups.google.com/d/optout.
