In my script I add the series of name-values to the data column. as Follows
for (var colmnName in MyResultHeader){
data.addColumn('number', colmnName);
}
I want the users to be able to filter by these columns for example
A | B | C | D
12 | 2 | 21 | 32
43 | 12| 23 | 21
How Can I add a Filter that has a dropdown (A,B,C,D) , So the selected the column will display on the chart?
ControlWrapper enforces us to mentions options': 'filterColumnIndex':
In my script I add the series of name-values to the data column. as Follows
for (var colmnName in MyResultHeader){
data.addColumn('number', colmnName);
}
I want the users to be able to filter by these columns for example
A | B | C | D
12 | 2 | 21 | 32
43 | 12| 23 | 21
How Can I add a Filter that has a dropdown (A,B,C,D) , So the selected the column will display on the chart?
ControlWrapper enforces us to mentions options': 'filterColumnIndex':
Share Improve this question asked Jun 18, 2013 at 5:48 Njax3SmmM2x2a0Zf7HpdNjax3SmmM2x2a0Zf7Hpd 1,3744 gold badges23 silver badges45 bronze badges1 Answer
Reset to default 7There is no direct support in Google Charts to let developers build controls such that users can select columns, but you can build it using a CategoryFilter as shown in this example by Andrew Gallant: http://jsfiddle/asgallant/WaUu2/
Here is the essence of that idea:
var columnsTable = new google.visualization.DataTable();
columnsTable.addColumn('number', 'colIndex');
columnsTable.addColumn('string', 'colLabel');
var initState= {selectedValues: []};
// put the columns into this data table (skip column 0)
for (var i = 1; i < data.getNumberOfColumns(); i++) {
columnsTable.addRow([i, data.getColumnLabel(i)]);
initState.selectedValues.push(data.getColumnLabel(i));
}
var columnFilter = new google.visualization.ControlWrapper({
controlType: 'CategoryFilter',
containerId: 'colFilter_div',
dataTable: columnsTable,
options: {
filterColumnLabel: 'colLabel',
ui: {
label: 'Columns',
allowTyping: false,
allowMultiple: true,
selectedValuesLayout: 'belowStacked'
}
},
state: initState
});
google.visualization.events.addListener(columnFilter, 'statechange', function () {
var state = columnFilter.getState();
var row;
var columnIndices = [0];
for (var i = 0; i < state.selectedValues.length; i++) {
row = columnsTable.getFilteredRows([{column: 1, value: state.selectedValues[i]}])[0];
columnIndices.push(columnsTable.getValue(row, 0));
}
// sort the indices into their original order
columnIndices.sort(function (a, b) {
return (a - b);
});
chart.setView({columns: columnIndices});
chart.draw();
});
columnFilter.draw();
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744128264a4559715.html
评论列表(0条)