Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript getting Datatable column names

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
like image 204
GROVER_SYAAN Avatar asked Dec 20 '22 16:12

GROVER_SYAAN


1 Answers

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

like image 193
GROVER_SYAAN Avatar answered Dec 22 '22 04:12

GROVER_SYAAN