簡體   English   中英

類型錯誤google.visualization.DataTable不是構造函數

[英]Type Error google.visualization.DataTable is not a constructor

我正在嘗試使用Google圖表創建表,但是它返回表方法的構造錯誤。 我看到了幾個參考,但是我認為錯誤是jsapi庫中給出的錯誤,因此google未定義。

> Uncaught TypeError: Cannot redefine property: Map
    at defineProperty (<anonymous>)
    at gvjs_bc (jsapi_compiled_format_module.js:13)
    at jsapi_compiled_format_module.js:28
> Uncaught TypeError: Cannot read property 'Xc' of undefined
    at jsapi_compiled_default_module.js:33
> Uncaught TypeError: Cannot use 'in' operator to search for 'google' in undefined
    at gvjs_k (jsapi_compiled_format_module.js:33)
    at jsapi_compiled_bar_module.js:17
> Uncaught TypeError: Cannot use 'in' operator to search for 'google' in undefined
    at gvjs_k (jsapi_compiled_format_module.js:33)
    at jsapi_compiled_table_module.js:5
 > Uncaught (in promise) TypeError: google.visualization.DataTable is not a constructor
    at drawChartUsersActive (UsersActive:280)
    at drawCharts (UsersActive:276)
    at loader.js:248

這是我的html代碼,如您所見,它非常簡單,我只是想繪制表格,但總是將這些錯誤返回給我

<html>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.1/jquery.min.js"></script>
    <script src="https://www.gstatic.com/charts/loader.js"></script>
    <meta name="layout" content="bootstrap">
  </head>
  <body>
    <div class="cabecalho"></div>
    <div id="table_div"></div>

    <script type="text/javascript">
      google.charts.load('current', {
        packages: ['bar', 'corechart', 'table'],
        callback: drawCharts
      });

      function drawCharts() {
        drawChartUsersActive();
      }

      function drawChartUsersActive() {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'Name');
        data.addColumn('number', 'Salary');
        data.addColumn('boolean', 'Full Time Employee');
        data.addRows([
          ['Mike',  {v: 10000, f: '$10,000'}, true],
          ['Jim',   {v:8000,   f: '$8,000'},  false],
          ['Alice', {v: 12500, f: '$12,500'}, true],
          ['Bob',   {v: 7000,  f: '$7,000'},  true]
        ]);

        var table = new google.visualization.Table(document.getElementById('table_div'));

        table.draw(data, {showRowNumber: true, width: '100%', height: '100%'});
      }
    </script>
  </body>

</html>

您是否嘗試更換:

google.charts.load('current', {
    packages: ['bar', 'corechart', 'table'],
    callback: drawCharts
  });

  function drawCharts() {
    drawChartUsersActive();
  }

通過:

google.charts.load('current', {'packages':['table']});
google.charts.setOnLoadCallback(drawChartUsersActive());

它就是文檔中所寫的內容,因此也許可行;)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM