admin管理员组文章数量:1399971
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();
本文标签: javascriptHow to use Google Charts api Control Wrapper for header column filterStack Overflow
版权声明:本文标题:javascript - How to use Google Charts api Control Wrapper for header column filter? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744128263a2592054.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论