<!DOCTYPE html>
<html>
<head>
<p>
</p>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Year', 'BirthRate', 'AgeGroup'],
<?php
while ($row = mysqli_fetch_array($result))
{
//echo "[".$row["Year"].",". $row["BirthRate"]."],";
echo "[".$row["Year"].",". $row["BirthRate"] .",".$row["AgeGroup"]."],";
}
?>
]);
var options = {
title: 'Year by BirthRate',
hAxis: {title: 'Year', minValue: 1940, maxValue: 2000},
vAxis: {title: 'BirthRate', minValue: 0, maxValue: 275},
colors: ['#a52714', '#097138'],
legend: 'AgeGroup'
};
var chart = new google.visualization.ScatterChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>
Trying to make a google chart visualization depicting Year by Birth Rate with a legend/key for Age Group. I get errors that do not allow me to do this like SyntaxError: Unexpected identifier 'years'. Expected either a closing ']' or a ',' following an array element.