0
任何人都可以告訴我哪個是顯示/隱藏線條圖例的最佳方法(如果使用複選框來更改可見性)。如何在谷歌圖表中顯示和隱藏傳說
我應該在折線圖中有最多7個傳說。
我的代碼是下面:
function DrawGraph(chartsdata, title, charttype) {
//debugger;
google.charts.load('current', { 'packages': ['corechart'] });
google.charts.setOnLoadCallback(DrawChart);
function DrawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', '');
data.addColumn('number', '');
try {
var data = google.visualization.arrayToDataTable(chartsdata);
}
catch (e) {
//debugger;
//document.writeln(e);
}
var optionsBar = {
title: title,
isStacked: true,
hAxis: {
type: "datetime",
showTextEvery: 1,
ticks: [2016,2017,2018,2019,2020,2021,2022,2023]
},
legend: {
position: 'bottom',
textStyle: { fontSize: 12 }
}
};
var optionsLine = {
title: title,
//width: 500,
seriesType: 'line',
legend: {
position: 'bottom',
textStyle: { fontSize: 11 }
}
};
if (charttype == "line") {
var chart = new google.visualization.LineChart(document.getElementById('chartdiv'));
chart.draw(data, optionsLine);
}
else {
var chart = new google.visualization.ColumnChart(document.getElementById('chartdiv'));
chart.draw(data, optionsBar);
}
}
}
見[此答案](http://stackoverflow.com/ a/43004583/5090771)顯示/隱藏帶複選框的行的完整示例_and_保持每個系列的行顏色一致... – WhiteHat