2017-07-27 14 views
0

のプロパティ「getChartLayoutInterface」を読み取ることができませんが、私は最近、私はのコンソールエラーを与えていたに問題が発生しましたJS - - Googleのチャート未定義

<script type="text/javascript"> 

     // Load the Visualization API and the piechart package. 
     google.charts.load('current', {'packages':['corechart']}); 

     // Set a callback to run when the Google Visualization API is 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 from 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 and draw our chart, passing in some options. 
      var chart = new google.visualization.AreaChart(document.getElementById('chart_div')); 
      chart.draw(data, options); 
     } 
</script> 

全体のポイントは、グラフに同じサイズの背景画像を入れている、任意の助けをいただければ幸いです。私はGoogleのVizulation APIがロードされていないからだと見てきたものから、私のコードは次のようですなぜエラーがスローされているのかについて。あなたの問題は、あなたがそのオブジェクトを参照する前に定義されたオブジェクトのインスタンスを持っていない場合は、ご使​​用の環境が意志による「チャート」が前

var boundingBox = chart.getChartLayoutInterface().getChartAreaBoundingBox(); 

この行で参照されることに定義されていないという事実に存在する

答えて

1

常に 'undefined'を返します。

おそらく、 'chart'のインスタンスを再配置するとうまくいくでしょう。

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

これは、DOM操作のために参照する前に、チャートがDOMに存在することを保証します。

関連する問題