查看Programmatic Control Changes示例。您可以通过代码更改滑块的下限和上限:
document.getElementById('rangeButton').onclick = function() {
slider.setState({'lowValue': 2, 'highValue': 5});
slider.draw();
};
例如,如果您选择同时为5的低值和高值,则将仅显示包含指定列的该值的行。在第一个图表的 onmouseover 事件中调用它:
google.visualization.events.addListener(chart1, 'onmouseover', function (e) {
// get the value for x in the current row from the data table
var xValue = data.getValue (e.row, 0);
// set the new bounds of the slider
slider.setState({'lowValue': xValue, 'highValue': xValue});
// update the slider (and chart2)
slider.draw();
}
);
由于您不希望滑块可见,只需将其隐藏:
// the slider has been created with 'containerId': 'control'
document.getElementById ("control").style.display = "none";