简体   繁体   English

google.visualization.PieChart不是构造函数

[英]google.visualization.PieChart is not a constructor

I am using pie chart to show the data here is my code I have added the following script 我正在使用饼图来显示数据,这是我的代码,我添加了以下脚本

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

    <script type="text/javascript">
        google.charts.load('current', { 'packages': ['corechart', 'gauge'] });

and my function which is used to display chat:- 和我用来显示聊天的功能:-

self.DrawServiceGraph = function (obj) {
                var dataArray = new Array();
                dataArray.push(['Services', 'Total']);
                var subCat = ko.utils.arrayFirst(self.SelectedServiceSubCategoryList(), function (o) { return o.Id === obj.Id; });
                if (subCat !== undefined) {
                    $.each(subCat.SSC_List(), function (index, item) {
                        var value = parseInt(item.Value());
                        dataArray.push([item.SSC_Name, value]);
                    });

                    var data = google.visualization.arrayToDataTable(dataArray);

                    var options = {
                        title: '', height: 230, width: 330,
                        chartArea: { left: 0, width: '100%' },
                        legend: { position: 'right', alignment: 'start', maxLines: 5, textStyle: { fontSize: 10 } }
                    };

                    var chart = new google.visualization.PieChart(document.getElementById('Services-chart' + obj.Id));
                    chart.draw(data, options);
                }
            }

Then i got the error from line: 然后我从行中得到了错误:

google.visualization.Pie Chart is not a constructor and google.visualization.arrayToDataTable is not a constructor google.visualization.Pie Chart不是构造函数,google.visualization.arrayToDataTable不是构造函数

What should be the possible solutions to avoid this errors? 避免这种错误的可能解决方案是什么?

are you waiting for the load statement to finish? 您是否在等待load语句完成?

use the callback to know when it is ok to begin drawing... 使用callback函数知道何时可以开始绘图...

google.charts.load('current', {
  callback: function () {
    // begin drawing
  },
  packages: ['corechart', 'gauge']
});

-- or -- - 要么 -

google.charts.load('current', {
  packages: ['corechart', 'gauge']
});
google.charts.setOnLoadCallback(function () {
  // begin drawing
});

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM