我是谷歌图表的新手。我正在使用 Google 折线图。
我的 Google 折线图有 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);
}
}
});
希望这对你有帮助!!
关于google-visualization - 如何隐藏/显示谷歌图表中的线条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24774358/