Hi,
I'm new with Google Chart. I'm retrieving with PHP weather data from OpenWeather API.
I pass to javascript the 2 data arrays with dates and temperatures to build a data array used to the google chart.
My code is:
<script type="text/javascript">
var temp=new Array();
<?php
for($i=0;$i<count($temperature);$i++){?>
temp[<?php echo $i; ?>]="<?php echo "$temperature[$i]"; ?>";
<?php
}?>
var dataora=new Array();
<?php
for($i=0;$i<count($dataora);$i++){
?>
dataora[<?php echo $i; ?>]="<?php echo "$dataora[$i]"; ?>";
<?php
}?>
google.charts.load('current', {'packages':['line']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data2 = new Array();
data2[0] = [ 'Date', 'Temperature' ];
for (i = 0; i < temp.length; i++) {
data2[i + 1] = [ dataora[i], parseFloat(temp[i]) ];
}
var data = google.visualization.arrayToDataTable(data2, false);
document.write(JSON.stringify(data));
var options = {
chart: {
title: 'Previsioni Temperatura',
subtitle: 'in °C'
},
width: 1000,
height: 500,
}
};
var chart = new google.charts.Line(document.getElementById('chart_div'));
chart.draw(data, google.charts.Line.convertOptions(options));
}
</script>
<div id="chart_div" style="50%"></div>
Opening the console I see this error:
Uncaught Error: Container is not defined
Can someone help me to solve this error?
Thanks.