I have an html drop down that I want to connect with a google linechart in order to filter data. I have an event listener inside a setChartView
function. I want to set specific columns based on what the user selects.
In this case:
view.columns.push(columnsTable.getValue(4, 1));
view.columns.push(columnsTable.getValue(5, 1));
The problem is, I cannot put these view requests inside my if statements because they are not defined within the scope of the event listener. I can take my if statement out of the event listener and say
if (a.value == 'selectedValue')
but then the event listener only takes the default selected value (in this case, 'maint') and does not recognize changed valuea
.
How do I put my view requests
view.columns.push(columnsTable.getValue(4, 1));
view.columns.push(columnsTable.getValue(5, 1));
inside my listener? And have these setChartView
values recognized within the listener?
I've tried adding setChartView
to the Listener parameters, calling setChartView
after the function declaration and have been referencing this https://www.w3schools.com/jsref/met_document_addeventlistener.asp
I feel like I'm missing something quite simple?
function setChartView(linechart, columnsTable, columnFilter) {
var state = columnFilter.getState();
var row;
var view = {
columns: [0]
};
var a = document.getElementById('select');
a.addEventListener('change', function() {
if (this.value = 'maint'){
console.log('maint');
} else if (this.value = 'ru'){
console.log('ru');
} else if (this.value = 'sf'){
console.log('sf');
}
}, false);
view.columns.push(columnsTable.getValue(4, 1));
view.columns.push(columnsTable.getValue(5, 1));
// sort the indices into their original order
view.columns.sort(function (a, b) {
return (a - b);
});
linechart.setView(view);
linechart.draw();
}// end setChartView