i am using Google charts to build stacked bar charts, created a listener to handler onclick event. there are three columns (site Name, Completed and Incomplete). i want listener to capture whether user clicked completed or incomplete, when i click on the first row data this is what i am getting. i know in my getColumnLabel method i am getting all column names but i want that to be captured based upon what user clicked
//my datatable
var data2 = new google.visualization.DataTable();
data2.addColumn('string', 'Site Name');
data2.addColumn('number', 'Completed');
data2.addColumn('number', 'Incomplete');
data2.addRows([
[Site1, 12, 7],
[Site2, 10, 9],
[Site3, 15, 4],
[Site4, 10, 5]
]);
//listener function
var selection = ChartName.getSelection();
var row = selection[0].row;
data2.getColumnLabel(0); //givesme: SiteName
data2.getColumnLabel(1); //givesme: Completed
data2.getColumnLabel(2) //givesme: Incompleted
data2.getValue(row, 0); //givesme: Site1
data2.getValue(row, 1); //givesme: 12
i have managed to find the solution, for reference if anyone is interested
var ColName1 = data2.getColumnLabel(selection.column);
so selection.column property gives you the selected column from the datatable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With