If you click an element twice in a row, the second click deselects the
element, thus the selection array is empty. Index 0 of an empty array is
undefined. You should test the length of the array before attempting to
access its contents:
function timeLineSelected(){
var selection = chartTimeLine.getSelection();
if (selection.length) {
alert(selection[0].row);
}
}
On Wednesday, June 18, 2014 2:52:14 PM UTC-4, JProject wrote:
>
> 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.