javascript - How to show and hide legends in google chart -
could let me know best method show/hide line legends (if using checkbox changing visibility).
i should having maximum 7 legends in line chart.
my code below:
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); } } }
toggle legend using none
/bottom
position:
legend: {position: 'none'} //to hide
Comments
Post a Comment