以下是https://developers.google.com/chart/interactive/docs/drawing_charts#chartwrapper字面上的一些代码
它应该显示ColumnChart,但它不会产生任何输出。相反,会发生JavaScript错误
独立加载文件时,loader.js:135 Uncaught TypeError: Cannot read property 'length' of undefined
中的错误为loader.js:135
知道如何解决这个问题吗?
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current'); // Don't need to specify chart libraries!
google.charts.setOnLoadCallback(drawVisualization);
function drawVisualization() {
var wrapper = new google.visualization.ChartWrapper({
chartType: 'ColumnChart',
dataTable: [['', 'Germany', 'USA', 'Brazil', 'Canada', 'France', 'RU'],
['', 700, 300, 400, 500, 600, 800]],
options: {'title': 'Countries'},
containerId: 'vis_div'
});
wrapper.draw();
}
</script>
</head>
<body style="font-family: Arial;border: 0 none;">
<div id="vis_div" style="width: 600px; height: 400px;"></div>
</body>
</html>
&#13;
答案 0 :(得分:1)
在某一点上,它可以在不加载任何packages
但是,对于最近的版本,使用'corechart'
loader.js
包
见以下,工作示例......
google.charts.load('current', {packages: ['corechart']});
google.charts.setOnLoadCallback(drawVisualization);
function drawVisualization() {
var wrapper = new google.visualization.ChartWrapper({
chartType: 'ColumnChart',
dataTable: [['', 'Germany', 'USA', 'Brazil', 'Canada', 'France', 'RU'],
['', 700, 300, 400, 500, 600, 800]],
options: {'title': 'Countries'},
containerId: 'vis_div'
});
wrapper.draw();
}
&#13;
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="vis_div" style="width: 600px; height: 400px;"></div>
&#13;