Google Maps Container not defined. But there is a div

My JS is on the POSTs page to generate the PHP script diagrams, and what the PHP script returns is added to the page (.html () div). However, using the Google Charts API, the page is empty. I get an error Container not defined from google library. This is what the PHP script passes:

<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 did document.getElementByID return null if chartContent is equipped? ''

EDIT : Now the warning is not displayed, but the page is still empty.

+4
source share
1 answer

You need to wait for data to download from Google. Check the api documentation, in the first example there is google.setOnLoadCallback(drawChart); instead of drawChart()

You call drawChart too soon before loading the drawing

+1
source

All Articles