English 中文(简体)
Can t 获取外部数据进入ExtJS(Sencha Touch)图表
原标题:Can t get external data into ExtJS (Sencha Touch) chart

EDIT: ANSWERED Worked it out. Posting to Stack Overflow actually pointed me to the answer!

Basically it appears there s something funny about Ext.data.JsonStore with Sencha Touch. Maybe some of the defaults aren t exactly as expected. Renamed the file to test.json (not sure if that was neccessary)

。 如何分类这种xml数据格式? 工作

Ext.regModel( tester , {
         idProperty:  name ,
         fields: [ name ,  data1 ,  data2 ,  data3 ]
     });
      var store = new Ext.data.Store({
         model:  tester ,
         autoLoad: true,
         proxy: {
             type:  ajax ,
             method:  GET ,
             url:  test.json ,
             reader: {
                 type:  json ,
                 root:  test 
             }
         },
         listeners: {
             load: function(obj, records){
                 Ext.each(records, function(rec){
                     console.log(rec.get( name ));
                 });
             }
         }
     }); 

ORIGINAL QUESTION

I m sure there s some major thing i m not doing right but i m having trouble getting data into a chart from a JSON source.

这是我下面的《仓储法典》,是一纸 working。

    window.store1 = new Ext.data.JsonStore({
         autoload: true,
         url:  test.php ,
      root:  test ,
         idProperty:  name ,     
         fields: [ name ,  data1 ,  data2 ,  data3 ]
     });

地点

测试.php =

{ "test" : {
        "data": [
          { "name": "Mon", "data1":47.5, "data2":20,    "data3":10},
                { "name": "Tue", "data1":30, "data2":30, "data3":30},
                { "name": "Wed", "data1":31.1, "data2":40, "data3":20},
                { "name": "Thu", "data1":21.1, "data2":20, "data3":30},
                { "name": "Fri", "data1":20.7, "data2":20, "data3":10},
                { "name": "Sat", "data1":22.4, "data2":30, "data3":30},
                { "name": "Sun", "data1":28.3, "data2":40, "data3":20}


        ]
    }
    }

如果我手把数据编成像以下的图表系列,则数据是正确的。

 window.store1 = new Ext.data.JsonStore({

            fields: [ name ,  data1 ,  data2 ,  data3 ],
            data: [
            { "name": "Mon", "data1":47.5, "data2":20, "data3":10},
            { "name": "Tue", "data1":30, "data2":30, "data3":30},
            { "name": "Wed", "data1":31.1, "data2":40, "data3":20},
            { "name": "Thu", "data1":21.1, "data2":20, "data3":30},
            { "name": "Fri", "data1":20.7, "data2":20, "data3":10},
            { "name": "Sat", "data1":22.4, "data2":30, "data3":30},
            { "name": "Sun", "data1":28.3, "data2":40, "data3":20}
            ]
        });

绘制脱蚊图(新信 Touch图)产生一个数据阵列,如此,我可以找到一个通过简单的JSON来源进行居住的例子。

window.generateData = function(n, floor) {
            var data = [],
                p = (Math.random() * 11) + 1,
                i;

            floor = (!floor && floor !== 0) ? 20 : floor;

            for (i = 0; i < (n || 12); i++) {
                data.push({
                    name: Date.monthNames[i % 12],
                    2008: Math.floor(Math.max((Math.random() * 100), floor)),
                    2009: Math.floor(Math.max((Math.random() * 100), floor)),
                    2010: Math.floor(Math.max((Math.random() * 100), floor)),
                    data1: Math.floor(Math.max((Math.random() * 100), floor)),
                    data2: Math.floor(Math.max((Math.random() * 100), floor)),
                    data3: Math.floor(Math.max((Math.random() * 100), floor)),
                    data4: Math.floor(Math.max((Math.random() * 100), floor)),
                    data5: Math.floor(Math.max((Math.random() * 100), floor)),
                    data6: Math.floor(Math.max((Math.random() * 100), floor)),
                    data7: Math.floor(Math.max((Math.random() * 100), floor)),
                    data8: Math.floor(Math.max((Math.random() * 100), floor)),
                    data9: Math.floor(Math.max((Math.random() * 100), floor)),
                    time: Math.floor(Math.max((Math.random() * 100), floor)),
                    registrations: Math.floor(Math.max((Math.random() * 100), floor)),
                    hours: Math.floor(Math.max((Math.random() * 100), floor)),
                    iphone: Math.floor(Math.max((Math.random() * 100), floor)),
                    android: Math.floor(Math.max((Math.random() * 100), floor)),
                    ipad: Math.floor(Math.max((Math.random() * 1000), floor))
                });
            }
            return data;
        };

 window.store2 = new Ext.data.JsonStore({
            fields: [ name ,  2008 ,  2009 ,  2010 ,  data4 ,  data5 ,  data6 ,  data7 ,  data8 ,  data9 ],
            data: generateData(6, 20)
        });

I d really appreciate if someone could point me in the right direction as to why the series data isn t loading.

问题回答
window.generateData = function() {
        var data = [{name:"January", iphone:43, android:70, blackberry:20}, {name:"February", iphone:23, android:10,  blackberry:20}, {name:"March", iphone:64, android:47, ipad:66,  blackberry:20}, {name:"April", iphone:12, android:29, ipad:67,  blackberry:20}, {name:"May", iphone:62, android:97, ipad:94,  blackberry:20}];
        return data;        
        };

我假定你有正确的途径,可以进入<条码>测试.php,你不再试图从不同地点开放。 您的初生是否有效? 您能否检查(与WireBug s一样)test.php装上了ok?

我仅附上报价中的数字值(>)。

使用模型,适当配置代用器。 我认为,必须检验你的根源。 数据





相关问题
ExtJS load form items/fields from database

I am using ExtJS 3 here. I would like to populate a formpanel from database with fields to be submitted. Basically, I don t know witch fields my form will have and I want to generate all formpanel ...

How to use Ext JS for role based application

I am planning to use Ext JS for a large application. The application s features are role based. When user login, they only see menu and screen features related to them. My server side technology will ...

Dynamically adding a TabPanel to a Panel Region

I have a Panel layout with a TreePanel in one region. A user clicks on an node in the tree and a TabPanel should be displayed in another region with information, editing tools etc. for that tree node....

How to embed Json result within Extjs Panel?

I have some issues with Json result and embed it within the html of the Extjs Panel. Here s that I have managed to get so far. myPanel is embedded within a mainPanel, and I have some shows/hide of ...

Ajax data update. Extjs

I need to keep certain data ( in a grid) up to date and was gonna do a poll to the server every 15 seocnds or so to get the data and refresh the grid, however it feels a bit dirty ( the grid will have ...

Better way to call superclass method in ExtJS

All the ExtJS documentation and examples I have read suggest calling superclass methods like this: MyApp.MyPanel = Ext.extend(Ext.Panel, { initComponent: function() { // do something MyPanel ...

Merged Headers in Ext JS Grid

Is it possible to have two headers in Ext JS grids? I have to show my grid as grouped data.. for example product types and products. In my case I need a grid like this: Field | Product Type A ...

热门标签