简体   繁体   English

Google Charts API:new google.visualization.Table() - Uncaught TypeError:undefined不是函数

[英]Google Charts API: new google.visualization.Table() - Uncaught TypeError: undefined is not a function

I have copied the Google Code example into a php script however I am getting the error "undefined is not a function" 我已将Google Code示例复制到php脚本中但是我收到错误“undefined is not a function”

it is happening specifically on this line: 它发生在这条线上:

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

It appeats that the Table function does not exist??? 它表明Table函数不存在???

I have copied the code directly from Googles Code examples so I can't understand what I have done wrong... I'm tending to believe that there is an issue with the example but I'm gonna assume I'd make a mistake before google would? 我直接从谷歌代码示例中复制了代码,所以我无法理解我做错了什么...我倾向于相信这个例子有问题,但我会假设我犯了一个错误谷歌之前会吗?

Code was copied directly from: http://code.google.com/apis/chart/interactive/docs/examples.html#interaction_example 代码直接从以下位置复制: http//code.google.com/apis/chart/interactive/docs/examples.html#interaction_example

You need to wait for the scripts to load. 您需要等待脚本加载。 For example: 例如:

  // Load the Visualization API and the piechart package.
  google.load('visualization', '1.0', {'packages':['table']});

  // Set a callback to run when the Google Visualization API is loaded.
  google.setOnLoadCallback(drawChart);

  function drawChart() {
       var table = new google.visualization.Table(document.getElementById('table_sort_div'));
  }

should work, because the scripts have been loaded. 应该工作,因为脚本已加载。 A better table reference here 这里有更好的表格参考

此外,如果您想加载多个包,您也可以这样做:

 google.load('visualization', '1', { packages: ['corechart', 'table'] });
    google.charts.load('current', {'packages': ['table']});
    google.charts.setOnLoadCallback(drawTable);

    function drawTable() {

      var data = new google.visualization.DataTable();
      data.addColumn('string', 'Name');
      data.addColumn('number', 'Salary');
      data.addColumn('boolean', 'Full Time');
      data.addRows(5);
      data.setCell(0, 0, 'John');
      data.setCell(0, 1, 10000, '$10,000');
      data.setCell(0, 2, true);
      data.setCell(1, 0, 'Mary');
      data.setCell(1, 1, 25000, '$25,000');
      data.setCell(1, 2, true);
      data.setCell(2, 0, 'Steve');
      data.setCell(2, 1, 8000, '$8,000');
      data.setCell(2, 2, false);
      data.setCell(3, 0, 'Ellen');
      data.setCell(3, 1, 20000, '$20,000');
      data.setCell(3, 2, true);
      data.setCell(4, 0, 'Mike');
      data.setCell(4, 1, 12000, '$12,000');
      data.setCell(4, 2, false);

      var table = new google.visualization.Table(document.getElementById('table_div'));
      table.draw(data, {showRowNumber: true, width: '100%', height: '100%'});

      google.visualization.events.addListener(table, 'select', function () {
        var row = table.getSelection()[0].row;
        alert('You selected ' + data.getValue(row, 0));
      });
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从带有jQuery的google.visualization.table中隐藏列 - how to hide a column from google.visualization.table w/ jquery 谷歌热图 API - visualization_impl.js:2 Uncaught (in promise) TypeError: Cannot read property 'NaN' of undefined - google heatmap API - visualization_impl.js:2 Uncaught (in promise) TypeError: Cannot read property 'NaN' of undefined Google可视化API google.charts.Bar(chartDiv)返回未定义 - Google Visualization API google.charts.Bar(chartDiv) returns undefined Google URL Shortener API-未捕获的TypeError:undefined不是函数 - Google URL shortener API - Uncaught TypeError: undefined is not a function 单击表格中的行时出现新的 Google 图表错误。 Uncaught TypeError: b.split is not a function -- 已经工作了好几年 - New Google Charts Error when clicking on row in table. Uncaught TypeError: b.split is not a function -- Has been working for several years 类型错误:google.visualization 未定义 - TypeError: google.visualization is undefined 使用 Google Analytics API 的面积图 - 未捕获的 TypeError 无法读取未定义的“库” - Area Charts Using Google Analytics API - Uncaught TypeError Cannot Read 'libraries' of undefined 谷歌图表:未捕获类型错误:google.loader.writeLoadTag 不是 function - Google charts: Uncaught TypeError: google.loader.writeLoadTag is not a function Uncaught TypeError:未定义不是函数-Google Chrome问题 - Uncaught TypeError: undefined is not a function - Google chrome issue 类型错误:google.visualization 未定义 - TypeError: google.visualization is undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM