2

今天早上我一直在想办法解决这个问题,我有一个 Extjs 窗口,我想在其中放置一个图表作为一个项目。我正在使用 Extjs 4,这是我的窗口:

Ext.define('Metrics.view.ChartWin', {   
extend: ['Ext.window.Window'],  
alias: 'widget.chartwin',   
requires :['Ext.chart.*','Ext.Window', 'Ext.fx.target.Sprite', 'Ext.layout.container.Fit', 'Ext.window.MessageBox', 'Metrics.view.DrawChart'],
    width: 800,
    height: 600,
    minHeight: 400,
    minWidth: 550,
    hidden: false,
    shadow: false,
    maximizable: true,
    title: 'Area Chart',
    renderTo: Ext.getBody(),
    layout: 'fit',
    tbar: [{
        text: 'Save Chart',
        handler: function() {
            Ext.MessageBox.confirm('Confirm Download', 'Would you like to download the chart as an image?', function(choice){
                if(choice == 'yes'){
                    chart.save({
                        type: 'image/png'
                    });
                }
            });
        }
    }],
    items:[{
                    //I guess the problem comes from here??
        xtype : 'drawchart'
    }]
    });

我的图表:

Ext.define('Metrics.view.DrawChart', {   
extend: 'Ext.chart.Chart',  
alias: 'widget.drawchart',   
requires: ['Ext.chart.*'],
renderTo: Ext.getBody(),
width: 700,
height: 600,
animate: true,
store:  'GraphData',
shadow : true,
legend: {
            position: 'right'
        },
axes: [
    {
        title: 'Week',
        type: 'Numeric',
        position: 'left',
        fields: ['Week'],
    grid : true

    },
    {
        title: 'In Out Backlog',
        type: 'Numeric',
        position: 'bottom',
        fields: ['BL1 Alt']

    }
],

theme: 'Red',


series: [
 {
 //BLA BLA BLA    
 }]
 }); 

我的图表工作正常。现在请告诉我,如何将此图表添加到我的窗口中?我收到此错误消息:

 Cannot read property 'isInstance' of undefined 

谢谢你。

4

1 回答 1

3

消除

renderTo: Ext.getBody()

从您的图表定义中。图表应在窗口中呈现。然后实例化一个窗口并将图表设置为那里的项目:

Ext.create('Ext.window.Window', {
...
items: [{
    xtype: 'drawchart'
}]
...

看这里的代码:http: //jsfiddle.net/AMx6r/1282/

于 2012-12-13T00:42:53.047 回答