javascript - JS - Google charts - Cannot read property 'getChartLayoutInterface' of undefined -


i've encountered issue in i'm given console error of:

cannot read property 'getchartlayoutinterface' of undefined 

i've read on other questions , i've seen it's because google vizulation api has not loaded, code following:

<script type="text/javascript">          // load visualization api , piechart package.         google.charts.load('current', {'packages':['corechart']});          // set callback run when google visualization api loaded.         google.charts.setonloadcallback(drawchart);          function drawchart() {           var jsondata = $.ajax({               url: "assets/main/getfrontdata.php",               datatype: "json",               async: false,               type: 'post',               }).responsetext;           var data = new google.visualization.datatable(jsondata);           var options = {             backgroundcolor: 'none',             linewidth: 4,             areaopacity: .2,             legend: { position: 'none' },             colors: ['#007cb0'],             width: 550,             height: 300           }               // create our data table out of json data loaded server.            var boundingbox = chart.getchartlayoutinterface().getchartareaboundingbox();     $('#backgroundchart').css('background-position', boundingbox.left + "px " + boundingbox.top + "px").css('background-size', boundingbox.width + "px " + boundingbox.height + "px");            // instantiate , draw our chart, passing in options.           var chart = new google.visualization.areachart(document.getelementbyid('chart_div'));           chart.draw(data, options);         } </script> 

the whole point being put background image in graph same size, appreciated on why error being thrown.

your problem exists due fact 'chart' undefined prior being referenced in line

 var boundingbox = chart.getchartlayoutinterface().getchartareaboundingbox();  

if not have instance of object defined before referencing object, environment return 'undefined'.

perhaps relocating instance of 'chart' well. move section above bounding box instantiation:

var chart = new google.visualization.areachart(document.getelementbyid('chart_div')); chart.draw(data, options);` 

this ensure chart exists in dom, before referencing dom manipulation.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -