简体   繁体   中英

extjs 4Uncaught TypeError: Cannot read property 'items' of undefined

i want load a chart with store and model by sample data.But when loading data get a error: Cannot read property 'items' of undefined i creating a store and model in conroller and set chart values:

var chart = Ext.create('Ext.chart.Chart', {
                    animate: true,
                    store: Ext.create('Ext.data.Store', {
                        model: Ext.create('Ext.data.Model', {
                                fields: ['temperature', 'date']
                            }
                        ),
                        data: [
                            {temperature: 58, date: new Date(2011, 1, 1, 8)},
                            {temperature: 63, date: new Date(2011, 1, 1, 9)},
                            {temperature: 73, date: new Date(2011, 1, 1, 10)},
                            {temperature: 78, date: new Date(2011, 1, 1, 11)},
                            {temperature: 81, date: new Date(2011, 1, 1, 12)}
                        ]
                    }),
                    axes: [{
                        type: 'numeric',
                        position: 'left',
                        title: 'y',
                        minimum: 0
                    },
                        {
                            type: 'date',
                            position: 'bottom',
                            title: 'x',
                            minimum: 0
                        }],
                    series: [{
                        type: 'column',
                        axis: 'left',
                        highlight: true,
                        tips: {
                            trackMouse: true,
                            width: 140,
                            height: 28
                        }
                    },
                        {
                            label: {
                                display: 'insideEnd',
                                'text-anchor': 'middle',
                                renderer: Ext.util.Format.numberRenderer('0'),
                                orientation: 'vertical',
                                color: '#333'
                            },
                        }
                    ],
                });

and i want add this chart to panel

Ext.ComponentQuery.query('panel')[0].add(chart);

Cannot read property 'items' of undefined is coming as you are directly creating instance of model with out defining .

Here is the fiddle http://jsfiddle.net/djaydxnd/66/

 store: Ext.create('Ext.data.Store', {
       model:Ext.define('chart', {
           extend: 'Ext.data.Model',
           fields: ['temperature','date']
       }),                      
       data: [
                                  {temperature: 58, date: new Date(2011, 1, 1, 8)},
                                {temperature: 63, date: new Date(2011, 1, 1, 9)},
                                {temperature: 73, date: new Date(2011, 1, 1, 10)},
                                {temperature: 78, date: new Date(2011, 1, 1, 11)},
                                {temperature: 81, date: new Date(2011, 1, 1, 12)}

      ]
     })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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