admin管理员组文章数量:1291002
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 Inplete). i want listener to capture whether user clicked pleted or inplete, 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', 'Inplete');
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: Inpleted
data2.getValue(row, 0); //givesme: Site1
data2.getValue(row, 1); //givesme: 12
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 Inplete). i want listener to capture whether user clicked pleted or inplete, 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', 'Inplete');
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: Inpleted
data2.getValue(row, 0); //givesme: Site1
data2.getValue(row, 1); //givesme: 12
Share
Improve this question
edited Mar 20, 2014 at 15:43
GROVER_SYAAN
asked Mar 20, 2014 at 15:33
GROVER_SYAANGROVER_SYAAN
3651 gold badge6 silver badges18 bronze badges
5
-
Does
selection[0]
have a column attribute? reference – mgilson Commented Mar 20, 2014 at 15:38 - selection[0] is it not the selected row? not too sure. – GROVER_SYAAN Commented Mar 20, 2014 at 16:04
- selection[0] is it not the selected row? not too sure. i want to get the column name that the user has selected data from so in my example i want to know if those numbers are ing from pleted or inplete so instead of saying data2.getColumnLabel(1) for pleted and data2.getColumnLabel(2) for Inplete it should be based upon the index of the column – GROVER_SYAAN Commented Mar 20, 2014 at 16:12
-
A word of caution: before you call
selection[0].row
, you should check to make sure that an element was selected in the first place, because deselecting an element also fires theselect
event, soselection
might be a zero-length array. – asgallant Commented Mar 20, 2014 at 16:59 - your question is irrelevant to my problem, but your code helped me solve my problem!! thanks! – AndrewBramwell Commented May 5, 2016 at 3:01
1 Answer
Reset to default 12i 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
本文标签: google visualizationJavascript getting Datatable column namesStack Overflow
版权声明:本文标题:google visualization - Javascript getting Datatable column names - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741505324a2382286.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论