TimeLine Chart getSelection how to get row?

1,050 views
Skip to first unread message

Григорий Сердюченко

unread,
Nov 3, 2014, 5:29:29 AM11/3/14
to google-visua...@googlegroups.com
I have next TimeLine Chart


google
.setOnLoadCallback(drawChart);
function drawChart() {
 
var container = document.getElementById('timechart');
 
var chart = new google.visualization.Timeline(container);
 
var dataTable = new google.visualization.DataTable();
  dataTable
.addColumn({ type: 'string', id: 'Room' });
  dataTable
.addColumn({ type: 'string', id: 'Name' });
  dataTable
.addColumn({ type: 'date', id: 'Start' });
  dataTable
.addColumn({ type: 'date', id: 'End' });
  dataTable
.addRows([
   
[ 'Magnolia Room',  'row 1',    new Date(0,0,0,9,0,0),  new Date(0,0,0,14,0,0) ],
   
[ 'Magnolia Room',  'row 2',    new Date(0,0,0,14,30,0), new Date(0,0,0,16,0,0) ],
   
[ 'Magnolia Room',  'row 3',    new Date(0,0,0,16,30,0), new Date(0,0,0,18,0,0) ],
   
[ 'Gladiolus Room', 'row 4',    new Date(0,0,0,12,30,0), new Date(0,0,0,14,0,0) ],
   
[ 'Gladiolus Room', 'row 5',    new Date(0,0,0,14,30,0), new Date(0,0,0,16,0,0) ],
   
[ 'Gladiolus Room', 'row 6',    new Date(0,0,0,16,30,0), new Date(0,0,0,18,0,0) ],
   
[ 'Petunia Room',   'row 7',    new Date(0,0,0,12,30,0), new Date(0,0,0,14,0,0) ],
   
[ 'Petunia Room',   'row 8',    new Date(0,0,0,14,30,0), new Date(0,0,0,16,0,0) ],
   
[ 'Petunia Room',   'row 9',    new Date(0,0,0,16,30,0), new Date(0,0,0,18,00,0) ]]);


 
var options = {
    colors
: ['#cbb69d', '#603913', '#c69c6e','#cbb69d', '#603913', '#c69c6e','#cbb69d', '#603913', '#c69c6e'],
    backgroundColor
: '#fff',
    enableInteractivity
: false,
   
 
};


  chart
.draw(dataTable, options);
 
  google
.visualization.events.addListener(chart, 'select', selectHandler);
 
 
function selectHandler(){
 
var selectedItem = chart.getSelection();
   
if (selectedItem) {
     
var value = dataTable.getValue(getSelection.row,1);   //row is undefined
      alert
('The user selected ' + value);
   
}
 
}
}

I need to see "The user selected row 1", when first row was clicked.
Where did I go wrong?

PS. Sorry for my bad English.

Григорий Сердюченко

unread,
Nov 3, 2014, 5:45:04 AM11/3/14
to google-visua...@googlegroups.com
Sorry.

var value = dataTable.getValue(selectedItem[0].row,1);      

Invalid row index undefined. Should be in the range [0-8]

Григорий Сердюченко

unread,
Nov 3, 2014, 6:35:35 AM11/3/14
to google-visua...@googlegroups.com
I find it.

var selectedItem = chart.getSelection();
var value = dataTable.getValue(selectedItem[0].bb,1)

I dont know why, but row-index is in "bb" property 

Daniel LaLiberte

unread,
Nov 3, 2014, 8:53:18 AM11/3/14
to google-visua...@googlegroups.com
This is a bug.  Thank you for reporting it.  The 'bb' property should be 'row', but it was obfuscated by the compiler.  We should have a fix for this in a future release, but in the meantime, you should check for both properties so your code will continue to work after this is fixed.  Do it like so:

  var selectedRow = (selectedItem[0].row != null) ? selectedItem[0].row : selectedItem[0].bb;
  var value = dataTable.getValue(selectedRow1)

--
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 google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.



--
dlaliberte@Google.com   5CC, Cambridge MA
daniel.laliberte@GMail.com 9 Juniper Ridge Road, Acton MA

Daniel LaLiberte

unread,
Nov 3, 2014, 8:57:50 AM11/3/14
to google-visua...@googlegroups.com
Actually, this bug ought to be fixed in the very near future, with the v40 release that we hope to push out in the next couple days.
Reply all
Reply to author
Forward
0 new messages