The issue is that I am not able to hide one of my dataserires from my chart when I call hideDataColumns() from my clickHandlerFunction. There are similar posts on this topic in here which I have walked through, but the problem still persists for me, and I was lacking a good example with the code.
You can see my complete code below, where you can also see that chart is defined globally.
I hope that you are able to advice me on this issue.
Br.
<html>
<head>
<style type="text/css">
@import url("style.css");
</style>
<link href="/apis/fusiontables/docs/samples/style/default.css"rel="stylesheet" type="text/css">
<script type='text/javascript'>
google.load('visualization', '1', {'packages':['annotatedtimeline']});
google.setOnLoadCallback(drawChart);
var chart;
function drawChart() {
var query = "SELECT 'YMD', " + "'Oil_Price_USD_bbl', 'Oil_Price_grGold_bbl'" + 'FROM 3405615';
var queryText = encodeURIComponent(query);
gvizQuery.send(function(response) {
chart = new google.visualization.AnnotatedTimeLine(document.getElementById('chart_div'));
chart.draw(response.getDataTable(),{
'displayAnnotations': false,
'colors': ['black', 'blue'],
'allowRedraw': true,
});
});
}
function handleButtonClick_USD() {
if (document.getElementById('Oil_USD').checked) {alert("USD ticked");}
else{
chart.hideDataColumns(1);
alert("USD unticked");
}
}
function handleButtonClick_GLD() {
if (document.getElementById('Oil_GLD').checked) {alert("GLD ticked");}
else{
chart.hideDataColumns(2);
alert("GLD unticked");
}
}
</script>
</head>
<body>
<div id='chart_div'>
</div>
<form name = "selectform">
Oil_USD: <input id='Oil_USD' type = "checkbox" name = "Oil_USD" checked="" onclick="handleButtonClick_USD()";/>
Oil_GLD: <input id='Oil_GLD' type = "checkbox" name = "Oil_GLD" checked="" onclick="handleButtonClick_GLD()" />
<br>
</form>
</body>
</html>