google.charts.load('current', {
callback: function () {
var data = google.visualization.arrayToDataTable([
['Project','PM','Year'],
['PRJ0001','John Doe',2012],
['PRJ0002','John Doe',2012],
['PRJ0003','John Doe',2012],
['PRJ0004','John Doe',2013],
['PRJ0005','Jackie Johnson',2012],
['PRJ0006','Jackie Johnson',2013],
['PRJ0007','Jackie Johnson',2014]
]);
var options = {
height: 400,
hAxis: {
viewWindow: {
min: 0,
max: 5
}
}
};
drawChart(data);
var slider = new google.visualization.ControlWrapper({
controlType: 'NumberRangeFilter',
containerId: 'filter_div',
dataTable: data,
options: {
filterColumnIndex: 2,
ui: {
format: {pattern: '0'}
}
}
});
google.visualization.events.addListener(slider, 'statechange', function () {
var range = slider.getState();
var view = new google.visualization.DataView(data);
view.setRows(data.getFilteredRows([{
column: 2,
minValue: range.lowValue,
maxValue: range.highValue
}]));
drawChart(view);
});
slider.draw();
function drawChart(dataTable) {
var dataGroup = google.visualization.data.group(
dataTable,
[1],
[{column: 1, aggregation: google.visualization.data.count, type: 'number', label: 'Count'}]
);
var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
chart.draw(dataGroup, options);
}
},
packages: ['controls', 'corechart']
});
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="filter_div"></div>
<div id="chart_div"></div>