Requirejs:CanvasJS.Chart不是构造函数

时间:2018-05-07 10:22:02

标签: requirejs amd canvasjs

我想使用requirejs使用canvasjs。像这样的代码:

require.config({
    shim: {
        'canvasjs' : {
            deps: ['jquery'],
            chart: {
                exports: 'Chart'
            }
        }
    },
    paths: {
        "jquery": "../js/jquery-1.10.2.min",
        "canvasjs": "../js/canvasjs.min"
    }
});

require(["jquery", "canvasjs"], function($, CanvasJS) {

        function AppViewModel() {
            var self = this;
        }

    var chart = new CanvasJS.Chart("chartContainer", {})
    }
)

但浏览器的控制台显示如下错误: enter image description here

代码有什么问题?感谢

1 个答案:

答案 0 :(得分:2)

看起来像名称冲突,从Require调用的回调参数中删除CanvasJS。

尝试关注

require.config({
    shim: {
        'canvasjs' : {
            deps: ['jquery'],
            chart: {
                exports: 'Chart'
            }
        }
    },
    paths: {
        "jquery": "../js/jquery-1.10.2.min",
        "canvasjs": "../js/canvasjs.min"
    }
});

    require(["jquery", "canvasjs"], function($) {

            function AppViewModel() {
                var self = this;
            }

        var chart = new CanvasJS.Chart("chartContainer", {})
        }
    )