javascript - 谷歌图表 : hi is not a function

标签 javascript html charts google-visualization

过去几天我一直在尝试执行我的 Google Charts 网页 ( jsfiddle ),但错误似乎一直在变化,即使我除了刷新网页之外没有做任何不同的事情。我尝试过使用 Chrome 的“清空缓存和硬重新加载”功能,但这并没有改变任何东西。我收到的错误包括诸如Uncaught typeError: hi is not a function之类的内容。我知道这段代码有效,因为我昨天使用了它并且它工作得很好。从代码工作到现在,我没有对代码进行任何更改。我是否导入了错误的内容,或者 Google Charts API 是否有问题。每当我尝试打开 Google's API 时,我都会遇到同样的问题

JavaScript:

google.charts.load('current',{'packages':['controls','corechart']});
google.charts.setOnLoadCallback(drawDashboard);

function drawDashboard(){
    var dataSet = google.visualization.arrayToDataTable([
        [{label:'date',type:'datetime'},{label:'Bytes from network:Bytes to network',type:'number'}],
        [new Date(2016,01,23,00,00),1.0],
        [new Date(2016,01,23,01,00),1.0075187969924813],
        [new Date(2016,01,23,03,00),1.126865671641791],
        [new Date(2016,01,24,22,00),0.987012987012987],
        [new Date(2016,01,25,01,00),1.0],
        [new Date(2016,01,25,02,00),0.9166666666666666],
        [new Date(2016,01,25,10,00),1.0],
        [new Date(2016,01,26,12,00),1.0],
        [new Date(2016,01,27,17,00),0.9864864864864865],
        [new Date(2016,01,28,22,00),0.03125],
        [new Date(2016,02,01,22,00),0.97],
    ]);

    var dashboard = new google.visualization.Dashboard(document.getElementById('dashboard_div'));

    var dateRangeFilter = new google.visualization.ControlWrapper({'controlType':'ChartRangeFilter',
                                                                   'containerId':'filter_div',
                                                                   'options':{
                                                                       'filterColumnLabel':'date',
                                                                       'ui':{
                                                                           'chartOptions':{
                                                                               'chartArea':{
                                                                                   'width':'90%'
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                   });

    var lineChart = new google.visualization.ChartWrapper({'chartType':'LineChart',
                                                           'containerId':'curve_chart',
                                                           'options':{
                                                               'title': 'Total Bytes from the Source Network to Total Bytes To the Source Network per Day',
                                                               'curveType': 'function',
                                                               'chartArea': {'height': '80%', 'width': '90%'},
                                                               'legend': 'none'
                                                           }
                                                          });

    dashboard.bind(dateRangeFilter,lineChart);

    dashboard.draw(dataSet);
}

html:

<html>
    <head>
        <link rel="stylesheet" href="styles.css">
        <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
        <script type="text/javascript">
            //javascript code from above
        </script>
    </head>
    <body>
        <h1>Data for this IP network</h1>
        <hr />
        <a href="../index.html">&lt&ltBACK TO INDEX</a>
        <div id="dashboard_div">
            <div id="curve_chart"></div>
            <div id="filter_div"></div>
        </div>
    </body>
</html>

CSS:

h1{
    text-align:center;
}
#dashboard_div{
    border:1px solid #ccc;
    margin:10px;
}
#curve_chart{
    width:915px;
    height:300px;
}
#filter_div{
    width:915px;
    height:50px;
}

最佳答案

这与加载器机制使用的缓存和重定向有关。谷歌可视化团队推出了一个新版本,让很多人崩溃了。修复到版本 43 或 44,而不是在加载程序调用中使用“当前”,应该可以暂时解决该问题。

参见https://github.com/google/google-visualization-issues/issues/2185

关于javascript - 谷歌图表 : hi is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35733045/

相关文章:

javascript - 获取坐标事件 map openlayers 4.6.5 ~ 5

html - 颜色 "Olive Green, Accent 3, Lighter 60%"的 html 是什么?

html - 桌面边框不会变色

javascript - 在chartjs中打印饼图

c++ - 通过 C++ 将 QML 项作为图像复制到剪贴板

javascript - HighChart 图表未在邮件中显示

Javascript:如果 hasClass 然后 addClass

javascript:如何首先加载页面的一部分

javascript - div位置与DOCTYPE效果的关系

performance - 如何提高 JavaFX 图表性能?