我是谷歌排行榜的新手。我正在使用Google折线图。
我的Google折线图中有两行。我应该可以使用check boxes
..
任何人都有任何想法来制作这个??
答案 0 :(得分:2)
不使用复选框,而是使用图例来隐藏/显示线条。
请参阅此answer
var sel = chart.getSelection();
// if selection length is 0, we deselected an element
if (sel.length > 0) {
// if row is null, we clicked on the legend
if (sel[0].row == null) {
var col = sel[0].column;
if (columns[col] == col) {
// hide the data series
columns[col] = {
label: data.getColumnLabel(col),
type: data.getColumnType(col),
calc: function () {
return null;
}
};
// grey out the legend entry
series[col - 1].color = '#CCCCCC';
}
else {
// show the data series
columns[col] = col;
series[col - 1].color = null;
}
var view = new google.visualization.DataView(data);
view.setColumns(columns);
chart.draw(view, options);
}
}
});
我希望这会对你有帮助!!
答案 1 :(得分:0)
JAVA SCRIPT代码检测复选框更改(我已将变量图表,数据和选项存储为全局变量,而不是在函数中以便在每个函数中使用它们):
$(document).ready(function() {
$('#id_of_the_checkbox').change(function () {
if ($('#id_of_the_checkbox').is(':checked')) {
var view = new google.visualization.DataView(data);
view.setColumns([0,1,2]); //the number of the columns that you want to show
chart.draw(view, options);
}
else {
var view = new google.visualization.DataView(data);
view.hideColumns([2]); //the number of the columns that you want to hide
chart.draw(view, options);
}
});
});
HTML输入复选框代码:
<input id="average" type="checkbox" name="average" value="Average" checked="checked"> Show my average consumption<br>
Google Chart DOC(setColumns):https://developers.google.com/chart/interactive/docs/reference#DataView_setColumns