问题描述
我使用Google图表构建堆叠条形图,为处理器onclick事件创建了一个监听器。
有三列(网站名称,已完成和未完成)。
我希望侦听器捕获用户是否点击
完成或不完整,当我点击第一行数据时,这就是我所得到的。
i知道在我的getColumnLabel方法中,我得到所有列名,但我希望根据用户点击来捕获它。
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]
]);
//监听器函数
var selection = ChartName.getSelection();
var row = selection [0] .row;
data2.getColumnLabel(0); // givenme:SiteName
data2.getColumnLabel(1); // givenme:已完成
data2.getColumnLabel(2)// Giveme:未完成
data2.getValue(row,0); // giveme:Site1
data2.getValue(row,1); // giveme:12
我设法找到解决方案,以供任何人有兴趣参考
var ColName1 = data2.getColumnLabel(selection.column);
因此selection.column属性为您提供了数据表中的选定列
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
这篇关于Javascript获取Datatable列名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!