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