我有以下指令:
angular.module('Division').directive('divisionChart', function () {
return {
restrict: 'E',
templateUrl: 'js/helpers/Division/directives/division-chart/division-chart.html',
scope: {},
link: function (scope, element, attr) {
var data = {
"cols": [
{"label": "Name", "pattern": "", "type": "string"},
{"label": "Manager", "pattern": "", "type": "string"},
{"label": "ToolTip", "pattern": "", "type": "string"}
],
"rows": [
{
"c": [
{"v": "1", "f": "Mike O."},
{"v": ""},
{"v": "The President"}
]
},
{
"c": [
{"v": "2", "f": "Jim"},
{"v": "1"},
{"v": "VP"}
]
},
{
"c": [
{"v": "3", "f": "Alice"},
{"v": "1"},
{"v": ""}
]
},
{
"c": [
{"v": "4", "f": "Bob"},
{"v": "2"},
{"v": "Bob Sponge"}
]
},
{
"c": [
{"v": "Carol"},
{"v": "4"},
{"v": ""}
]
}
]
};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.OrgChart(element[0]);
chart.draw(data);
}
}
});
具有以下HTML:
<div></div>
当我尝试运行此程序时,出现以下错误:
TypeError: a.S is not a function
我确保将googlechart包括在索引中:
<script src="http://www.google.com/jsapi?ext.js"></script>
<script>google.load('visualization', '1', {packages: ['orgchart']});</script>
那么谁能告诉我我做错了什么?
最佳答案
首先,建议为Google图表库使用当前的加载器...<script src="https://www.gstatic.com/charts/loader.js"></script>
根据release notes ...
通过jsapi
加载器仍然可用的Google Charts版本不再被一致更新。从现在开始,请使用新的静态加载程序(loader.js
)。
唯一更改的是load
语句,其后是...
google.charts.load('current', {
callback: drawChart,
packages: ['corechart']
});
请注意
callback
,与jsapi
加载程序一样,load
语句具有callback
在触发回调之前,您不应该从以下命名空间创建
google.charts
google.visualization
关于javascript - google chart a.S不是函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40419739/