2011-05-27 50 views
1

我想擴展chart類以在視圖中使用,作爲extjs4 MVC框架的一部分。我得到這個錯誤在Firebug:在extjs4 mvc framework中擴展chart類導致「config is undefined」

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); 
    }  
}); 
+0

你可以發佈完整的'CDR.chart.Daily'定義嗎? – rdougan 2011-06-20 17:09:07

回答

0

我也有過類似的問題但不是用於配置對象,而是用於基本主題,首先針對您的問題,您可以更正面板的項目屬性而不是

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

應該

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

此外,如果你正在使用的MVC框架,那麼要確保在app.js已添加以下線路中的Ext.require部分:

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

我認爲這是一個錯誤,因爲「主題」應與默認情況下,「基地」的價值,但還沒有。 從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'}]); 
}, 

這是爲我工作。