谷歌图表a.S不是一个功能

时间:2016-11-04 09:58:49

标签: javascript angularjs google-visualization

我有以下指令:

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>

所以有人能告诉我我做错了什么吗?

1 个答案:

答案 0 :(得分:1)

首先,建议使用Google图表库的当前加载程序...

<script src="https://www.gstatic.com/charts/loader.js"></script>

根据release notes ...

  

通过jsapi加载程序保留的Google图表版本不再一致更新。从现在开始,请使用新的gstatic加载程序(loader.js)。

唯一改变的是load语句,后跟......

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

注意callback,与jsapi加载器一样,load语句包含callback
在回调被触发之前,您不应该从以下命名空间创建

google.charts
google.visualization