echarts 使用AMD加载报对象不支持此操作问题解决

1、问题

echarts确实是一种展现非常强劲的JS图形工具,但文档太少。

在使用AMD加载echarts类时,总是报 “对象不支持此操作”错误:

d=new a(this._themeConfig,this._messageCenter,this._zr,e,this,l)

看了一下源码,错误为获取“grid”类型的component时出现undefined。


2、解决

在引入的方法中加入依赖:

define(['echarts','echarts/chart/line', 'echarts/chart/bar'], function(ec) {
    //...
} 

'echarts/chart/line', 'echarts/chart/bar']
是需要添加的部分。

其中echarts在公共的js(如common.js)中加载:

require.config({
    baseUrl: '../wx/scripts/',

    paths: {
        'jquery': 'lib/jquery/jquery.min',
        "echarts": "lib/echarts/echarts.amd",
    }

参考:

1、echarts引入问题:ComponentClass is not a function,我才是老K,http://www.oschina.net/question/2447445_248304

posted @ 2016-08-09 02:32  hongweigg  阅读(27)  评论(0)    收藏  举报