首页 > 解决方案 > 将 highcharts 版本从 4.1 升级到 7.12 出现错误 Uncaught ReferenceError: Highcharts is not defined

问题描述

我正在尝试升级 highcharts 版本,在控制台中不断出现错误 Uncaught ReferenceError: Highcharts is not defined

我的项目使用以下库 Jquery、dojo、骨干网、下划线。

这是我的 index.html 和我包含的库的顺序,我使用以下链接从下载的 highcharts 7.1.2下载 highcharts“ https://www.highcharts.com/blog/download/ ”

<!doctype html>
    <html lang="en">
        <head>
            <script>
                var dojoConfig = {
                        parseOnLoad: true,
                        locale: 'en',
                        async: true,
                    packages: [
                        { name: "app", location: location.pathname.replace(/[^\/]+$/, "") + "js/app" },             
                        { name: "bootstrapmap", location: location.pathname.replace(/[^\/]+$/, "") + "libs/bower/bootstrap-map-js/src/js", main: "bootstrapmap" },
                        { name: "backbone", location: location.pathname.replace(/[^\/]+$/, "") + "libs/bower/backbone", main: "backbone" },
                        { name: "underscore", location: location.pathname.replace(/[^\/]+$/, "") + "libs/bower/underscore", main: "underscore" }
                        ]
                    };
            </script>
                <script src="libs/jsapi/dojo/dojo.js" data-dojo-config="async: true"></script>
        </head>
        <body class="claro">
            <div class="loading">
                <img src="img/spinner.gif" class="loading-spinner" />
                <img src="img/loading.png" class="loading-img img-responsive" />
            </div>
            <script src="libs/bower/jquery/dist/jquery.js"></script>
            <script src="libs/bower/highcharts/highcharts.js"></script>
                <script src="libs/highcharts-regression.js"></script>
                <script src="libs/bower/highcharts/modules/exporting.js"></script>
                <script src="libs/bower/highcharts/modules/export-data.js"></script>
            <script src="libs/bootstrap.custom.js"></script>
            <script src="js/main.js"></script>
        </body>
    </html>

我正在尝试将 highcharts 版本从 4.1 升级到 7.1.2 并下载了捆绑的全新 highcharts 版本,在项目中添加了该捆绑包,并在 jquery、highchart js 和 highcharts-regression、导出和可访问性等模块之后在正文中添加了以下脚本标签对于我的项目,我在控制台中不断收到错误 Uncaught ReferenceError: Highcharts is not defined,如果我包含我的旧 4.1 版本,它工作正常,如果我包含新版本 Uncaught ReferenceError: Highcharts is not defined,我会一直收到错误,而我检查了导致该问题的窗口上不可用的 Highcharts,我不确定即使我包含了必需的库,我仍然会收到该错误。

最近的发现: 如果我将 4.1 版升级到 5 的任何版本,它都可以正常工作,升级到 6 或 7 版无法正常工作,得到Uncaught ReferenceError: Highcharts is not defined

标签: highcharts

解决方案


我找到了解决自己问题的方法,Dojo 是问题的原因。在dojo脚本标签导致发布后添加highchart库,

解决方案: 在dojo脚本标签之前添加highchart(7.1.2)脚本标签,效果很好

工作代码:

    <script src="libs/highcharts-regression.js"></script> 

    <script src="libs/bower/highcharts/modules/exporting.js"></script>

    <script src="libs/bower/highcharts/modules/export-data.js"></script>

    <script src="libs/bower/highcharts/modules/accessibility.js"></script>



    <script src="libs/jsapi/dojo/dojo.js" data-dojo-config="async: true"></script>

推荐阅读