I'm facing an issue while trying to open a link in a Google line chart using the selection handler. The chart stops rendering, and as a newcomer to javascript, I'm unsure why.
This is how the code is integrated into my HTML:
<pre><code><script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="tt_6_annotation" style="width: 100%; min-height: 300px; height:auto;"></div></pre></code>
This is the code snippet I am using:
google.charts.load('current', {
'packages': ['corechart']
});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var dataTable = new google.visualization.DataTable();
// Rest of the code for drawing the line chart...
}
// Issue lies here, the selection handler fails to work properly
var google.visualization.events.addListener(chart, 'select', function(){
// Grabbing values before redirecting
var selection = chart.getSelection();
var row = selection[0].row;
var col = selection[0].column;
var link = data.getValue(row, 4);
location.href = 'http://www.mywebsite.com/' + row;
});
The part that's causing trouble involves extracting a number from the DataTable to append it to the URL within the select function.
Looking for any insights or solutions to fix this issue.