Reputation: 7253
My JS on a page POSTs to a chart generation PHP script, and what the PHP script returns is then added to the page (.html() of an div). However, using the Google Charts API.. the page is blank. I get the error Container is not defined from google's library. Here's what the PHP script is passing:
<script>google.load('visualization', '1', {packages: ['corechart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Date', 'BTC Price'],['2013-02-12', 22.5]
]);
alert(document.getElementById('chart_div'));
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, {title: 'BTC/USD price'});
}</script><div id='chart_div' style='width: 900px; height: 500px;'></div>
Why would document.getElementByID return null when chartContent is there?'
EDIT: Now the alert does not show up, yet the page is still blank.
Upvotes: 4
Views: 9197
Reputation: 219
You need to wait for data load from google.
Check api documentation,
in first example there's
google.setOnLoadCallback(drawChart);
instead of drawChart()
You're calling drawChart too early, before drawchart's are loaded
Upvotes: 1