Search code examples
extjschartsmodelstore

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);

Solution

  • 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)}
    
          ]
         })