简体   繁体   English

如何在Panel中调用Ext.Define类?

[英]How to call Ext.Define class inside Panel?

I am new on Ext.js and trying to figure out basic structure. 我是Ext.js的新手,正在尝试弄清基本结构。 Anyway, I want to use LineChart inside the Panel, but I am getting this error: 无论如何,我想在面板内使用LineChart,但出现此错误:

**Uncaught Error: [Ext.create] Unrecognized class name / alias: BasicChart**

I found this code from http://dev.sencha.com/ext/5.1.0/examples/kitchensink/?charts=true#line-basic . 我从http://dev.sencha.com/ext/5.1.0/examples/kitchensink/?charts=true#line-basic找到了这段代码。 and here is the LineChart code: 这是LineChart代码:

 Ext.define('BasicChart', {
    extend: 'Ext.Panel',
    xtype: 'basic-line',
    requires:[
        'Ext.chart.Chart',
        'Ext.chart.axis.Numeric',
        'Ext.chart.axis.Category'],


    initComponent: function() {
        var me = this;

        this.myDataStore = Ext.create('Ext.data.JsonStore', {
            fields: ['month', 'data1' ],
            data: [
                { month: 'Jan', data1: 20 },
                { month: 'Feb', data1: 20 },
                { month: 'Mar', data1: 19 },
                { month: 'Apr', data1: 18 },
                { month: 'May', data1: 18 },
                { month: 'Jun', data1: 17 },
                { month: 'Jul', data1: 16 },
                { month: 'Aug', data1: 16 },
                { month: 'Sep', data1: 16 },
                { month: 'Oct', data1: 16 },
                { month: 'Nov', data1: 15 },
                { month: 'Dec', data1: 15 }
            ]
        });


        me.items = [{
            xtype: 'chart',
            width: '100%',
            height: 410,
            padding: '10 0 0 0',
            style: {
                'background' : '#fff'
            },
            animate: true,
            shadow: false,
            store: this.myDataStore,
            insetPadding: 40,
            items: [{
                type  : 'text',
                text  : 'Line Charts - Basic Line',
                font  : '22px Helvetica',
                width : 100,
                height: 30,
                x : 40, //the sprite x position
                y : 12  //the sprite y position
            }, {
                type: 'text',
                text: 'Data: Browser Stats 2012',
                font: '10px Helvetica',
                x: 12,
                y: 380
            }, {
                type: 'text',
                text: 'Source: http://www.w3schools.com/',
                font: '10px Helvetica',
                x: 12,
                y: 390
            }],
            axes: [{
                type: 'Numeric',
                fields: 'data1',
                position: 'left',
                grid: true,
                minimum: 0,
                label: {
                    renderer: function(v) { return v + '%'; }
                }
            }, {
                type: 'Category',
                fields: 'month',
                position: 'bottom',
                grid: true,
                label: {
                    rotate: {
                        degrees: -45
                    }
                }
            }],
            series: [{
                type: 'line',
                axis: 'left',
                xField: 'month',
                yField: 'data1',
                style: {
                    'stroke-width': 4
                },
                markerConfig: {
                    radius: 4
                },
                highlight: {
                    fill: '#000',
                    radius: 5,
                    'stroke-width': 2,
                    stroke: '#fff'
                },
                tips: {
                    trackMouse: true,
                    style: 'background: #FFF',
                    height: 20,
                    showDelay: 0,
                    dismissDelay: 0,
                    hideDelay: 0,
                    renderer: function(storeItem, item) {
                        this.setTitle(storeItem.get('month') + ': ' + storeItem.get('data1') + '%');
                    }
                }
            }]
        }];

        this.callParent();
    }
});

and here is the part of my main class, which is trying to call this chart inside the panel : 这是我的主要课程的一部分,它试图在面板内部调用此图表:

{
             xtype: 'panel',
             width: 1000,
             height: 1000,
             autoScroll: true,
             bodyPadding: 10,
             title:'Billing Graphs',
             margin: '10 5 0 5',
             colspan:2,
             items: Ext.create('BasicChart', {
             renderTo: Ext.getBody()
            })


         }

Please help me find what I am doing wrong with it. 请帮助我找出我做错了什么。 Hope I could explain well. 希望我能解释清楚。 Thanks for any help. 谢谢你的帮助。

You can use the xtype like this: 您可以像这样使用xtype

{
         xtype: 'panel',
         width: 1000,
         height: 1000,
         autoScroll: true,
         bodyPadding: 10,
         title:'Billing Graphs',
         margin: '10 5 0 5',
         colspan:2,
         items: {
           xtype: 'basic-line'
         }
     }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM