Javascript getting Datatable column names

女生的网名这么多〃 提交于 2020-01-11 09:37:09

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/22537784/javascript-getting-datatable-column-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!