在extjs4 mvc框架中扩展图表类导致“config is undefined”

时间:2011-05-27 18:13:40

标签: extjs extjs4 extjs-mvc

我想扩展图表类以在视图中作为extjs4 MVC框架的一部分使用。我在firebug中收到此错误:

config is undefined 
[Break On This Error] me.initTheme(config.theme || me.theme);
Chart....8936564 (line 191)

这是类定义:

Ext.define('CDR.chart.Daily', {
alias: 'widget.dailychart',
extend: 'Ext.chart.Chart',    
initComponent: function() {
    Ext.apply(this, {
        id: 'daily',
        insetPadding: 30,

     ... irrelevant code cut .......

    });          
    this.callParent(arguments);
  }
});

这是图表添加到的视图类:

Ext.define('CDR.view.trunk.View', {
alias: 'widget.trunkview',
extend: 'Ext.panel.Panel',    
requires: [
    'CDR.chart.Daily'
],        
initComponent: function() {
    Ext.apply(this, {
        id        : 'itemCt',
        border    : false,
        autoScroll: true,
        layout: {
            type : 'hbox',
        },            
        items: [
            Ext.create('CDR.chart.Daily'),
            {
                id    : 'contentCt',
                width : 500,
                border: false
            }
        ]
    });                
    this.callParent(arguments);
  }    
});

2 个答案:

答案 0 :(得分:2)

我认为这是一个错误,因为默认情况下'主题'应该带有'Base'值,但是没有。 来自Chart.js的源代码:

/**
 * @cfg {String} theme (optional) The name of the theme to be used. A theme defines the colors and
 * other visual displays of tick marks on axis, text, title text, line colors, marker colors and styles, etc.
 * Possible theme values are 'Base', 'Green', 'Sky', 'Red', 'Purple', 'Blue', 'Yellow' and also six category themes
 * 'Category1' to 'Category6'. Default value is 'Base'.
 */

因此,只需将以下代码添加到新类中:

constructor: function() {
    this.callParent([{theme: 'Category1'}]);
},

这对我有用。

答案 1 :(得分:0)

我也有类似的问题,但不是配置对象,但对于基本主题,首先你的问题可以纠正面板的items属性而不是

 items: [
        Ext.create('CDR.chart.Daily'),

应该是

项目:[            {Ext.create('CDR.chart.Daily'),....}

此外,如果您正在使用MVC框架,请确保在您的app.js中您已在Ext.require部分添加以下行:

'Ext.chart.theme.Base',
'Ext.chart.theme.Theme',