javascript - google.visualization.PieChart is not a constructor - Stack Overflow

I am using pie chart to show the data here is my codeI have added the following script<script type

I am using pie chart to show the data here is my code I have added the following script

<script type="text/javascript" src=".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

What should be the possible solutions to avoid this errors?

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./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

What should be the possible solutions to avoid this errors?

Share Improve this question asked Mar 10, 2017 at 9:33 Gaurav_0093Gaurav_0093 1,0307 gold badges30 silver badges58 bronze badges 1
  • 1 Please update your question with a runnable minimal reproducible example using Stack Snippets (the [<>] toolbar button) demonstrating the problem. – T.J. Crowder Commented Mar 10, 2017 at 9:35
Add a ment  | 

1 Answer 1

Reset to default 5

are you waiting for the load statement to finish?

use the callback to know when it is ok to begin drawing...

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
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744303928a4567638.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信