类型错误 google.visualization.DataTable 不是构造函数
Type Error google.visualization.DataTable is not a constructor
我正在尝试使用 google 图表创建 table,但它返回 table 方法的构造错误。我看到了几个参考,但我认为错误是在 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 代码,如您所见,它非常简单,我只是想绘制 table,但总是 returns 这些错误
<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: ',000'}, true],
['Jim', {v:8000, f: ',000'}, false],
['Alice', {v: 12500, f: ',500'}, true],
['Bob', {v: 7000, f: ',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());
这正是文档中所写的内容,所以也许有用 ;)
我正在尝试使用 google 图表创建 table,但它返回 table 方法的构造错误。我看到了几个参考,但我认为错误是在 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 代码,如您所见,它非常简单,我只是想绘制 table,但总是 returns 这些错误
<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: ',000'}, true],
['Jim', {v:8000, f: ',000'}, false],
['Alice', {v: 12500, f: ',500'}, true],
['Bob', {v: 7000, f: ',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());
这正是文档中所写的内容,所以也许有用 ;)