javascript - Uncaught Error: Container Is Not Defined - Google Charts -


i'm trying load google chart , getting following answer:

uncaught error: container not defined

i've read other questions message google charts , common problem seems if getelementbyid isn't working correctly.

however, don't believe issue me, or @ least not issue in same way others.

this google charts code have:

google.load('visualization', '1.0', {'packages':['gauge']});  google.setonloadcallback(drawchart);  function drawchart() {         var data = google.visualization.arraytodatatable([             ["label", "value"],             ["match", state.greens[0].score]         ]);          var options = {             redfrom: 90, redto: 100,             yellowfrom: 75, yellowto: 90,             minorticks: 5         };          var chart = new google.visualization.gauge(document.getelementbyid("chart-div"));         chart.draw(data, options);          setinterval(function() {             data.setvalue(0, 1, 40 + math.round(60 * math.random()));             chart.draw(data, options);             }, 13000); }; 

this point blank google has in gauge chart reference: https://developers.google.com/chart/interactive/docs/gallery/gauge

i'm literally trying use straightforward example docs generate chart data.

here's html have:

<div class="row">                 <div class="col-md-6 col-md-offset-3">                     <div class="chart-div">                     </div>                 </div>             </div> 

i have javascript in separate file, , load api in head of html file.

what missing?

document.getelementbyid("chart-div") looks element id set chart-div. div using class attribute instead of id attribute. change <div class="chart-div"></div> <div id="chart-div"></div>

alternatively, can document.getelementsbyclassname('chart-div')[0], 0 ordinal of element want. way may preferred, since post multiple charts on page; note getelementsbyclassname not supported in older browsers (pre ie-9)


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -