get the actual values from google visualization categorywrapper control

328 Views Asked by At

I have a sample google visualization controlwrapper here in this fiddle. How can I get the actual selected value of the control? ie, I drawn the control using column 1 and when I selected something, I want to get the values which are in column 1 instead of its formatted value like if I select CPU, the alert should be 1. I tried with following code and it returns only the formatted value.

google.visualization.events.addListener(chart, 'ready', function () {
         if (control.getState().selectedValues.length > 0) {
             alert(control.getState().selectedValues);
         }    
     });
1

There are 1 best solutions below

0
On BEST ANSWER

You could find selected row values as demonstrated below:

google.visualization.events.addListener(chart, 'ready', function () {

     var selectedVals = control.getState().selectedValues;
     var dt = control.getDataTable();
     var selectedIds = getFilteredValues(dt,selectedVals);        
     alert(selectedIds);
});    

where

function getFilteredValues(dataTable,values){
    var result = []; 
    for(i = 0; i< dataTable.getNumberOfRows();i++){
        var curVal = dataTable.getValue(i,0); 
        if(values.indexOf(curVal) > -1){
            var curId = dataTable.getValue(i,1);
            result.push(curId);
        }        
     }
     return result;
}

Example: JSFiddle