我有一个 Ext.chart 饼图,我正在尝试加载数据,但有点麻烦。
下面的静态存储工作正常:
this.myDataStore = Ext.create('Ext.data.JsonStore', {
fields: ['COUNTY', 'AMOUNT' ],
data: [
{ COUNTY: 'London', AMOUNT: 10.92 },
{ COUNTY: 'Lancashire ', AMOUNT: 6.61 },
{ COUNTY: 'Kent', AMOUNT: 5.26 },
{ COUNTY: 'West Yorkshire', AMOUNT: 4.52 },
{ COUNTY: 'Nottinghamshire', AMOUNT: 4.01 },
{ COUNTY: 'Others', AMOUNT: 68.68 }
]
});
然而这不是吗?
Ext.define('counties', {
extend: 'Ext.data.Model',
fields: [
{name: 'COUNTY', type: 'string'},
{name: 'AMOUNT', type: 'float'}
]
});
this.myDataStore = Ext.create('Ext.data.JsonStore', {
model: 'counties',
proxy: {
type: 'ajax',
url : '/dashboard/countytotals?percentage=true',
reader: {
type: 'json',
root: 'data'
}
},
autoLoad: true
});
我只是得到一个空白图表或未定义...?
当我使用 Data.Store(而不是 JsonStore)时,我可以看到饼图周围的县,但中间的彩色图表不见了,并且正在使用下面的 Data.Store:
Ext.define('APP.store.Countytotalsgraph', {
extend: 'Ext.data.Store',
model: 'APP.model.Countytotalsgraph',
autoLoad: true,
storeId: 'countyTotalsGraphStore',
proxy: {
type: 'ajax',
format: 'json',
api: {
read : '/dashboard/countytotals'
},
reader: {
type: 'json',
root: 'data',
//rootProperty: 'data',
successProperty: 'success'
}
},
listeners: {
beforeload: function(store, eOpts) {
//if ( this.data.items.length ) {
//Ext.getCmp('optionsGrid').getView().refresh();
//}
store.proxy.extraParams = {
percentage: 'true'
}
}
}
});
上面的代码片段产生了这个:
从我的数据库返回的 json 格式如下:
{"success":true,"data":[{"COUNTY":"London ","AMOUNT":10.92},{"COUNTY":"Lancashire","AMOUNT":6.61},{"COUNTY":"Kent ","AMOUNT":5.26},{"COUNTY":"West Yorkshire","AMOUNT":4.52},{"COUNTY":"Nottinghamshire","AMOUNT":4.01},{"COUNTY":"Other","AMOUNT":68.68}]}
第一个代码片段显示了一个很好的图表,其他人没有,你们能发现问题吗?
在此先感谢:) 内森
图表的完整代码
Ext.define('APP.view.core.graphs.Countytotals', {
extend: 'Ext.Panel',
alias: 'widget.gridportlet',
id: 'countyTotalsGraph',
xtype: 'pie-basic',
width: 650,
initComponent: function() {
var me = this;
Ext.define('counties', {
extend: 'Ext.data.Model',
allowNull: true,
fields: ['COUNTY', 'AMOUNT']
});
this.myDataStore = Ext.create('Ext.data.JsonStore', {
model: 'counties',
proxy: {
type: 'ajax',
url : '/dashboard/countytotals?percentage=true',
reader: {
type: 'json',
root: 'data'
}
},
autoLoad: false
});
this.listeners = {
afterrender: function(){
console.log('asdsadasd');
this.myDataStore.load();
}
};
/*this.myDataStore = Ext.create('Ext.data.JsonStore', {
fields: ['COUNTY', 'AMOUNT' ],
data: [
{ COUNTY: 'London', AMOUNT: 10.92 },
{ COUNTY: 'Lancashire ', AMOUNT: 6.61 },
{ COUNTY: 'Kent', AMOUNT: 5.26 },
{ COUNTY: 'West Yorkshire', AMOUNT: 4.52 },
{ COUNTY: 'Nottinghamshire', AMOUNT: 4.01 },
{ COUNTY: 'Others', AMOUNT: 68.68 }
]
});*/
console.log(this.myDataStore.getData());
me.items = [{
xtype: 'polar',
width: '100%',
height: 500,
store: this.myDataStore,
insetPadding: 50,
innerPadding: 20,
legend: {
docked: 'bottom'
},
interactions: ['rotate', 'itemhighlight'],
/*sprites: [{
type: 'text',
text: 'Pie Charts - Basic',
font: '22px Helvetica',
width: 100,
height: 30,
x: 40, // the sprite x position
y: 20 // the sprite y position
}, {
type: 'text',
text: 'Data: Top 5 Counties',
font: '10px Helvetica',
x: 12,
y: 425
}, {
type: 'text',
text: 'Source: Database',
font: '10px Helvetica',
x: 12,
y: 435
}],*/
series: [{
type: 'pie',
angleField: 'AMOUNT',
label: {
field: 'COUNTY',
display: 'outside',
calloutLine: {
length: 60,
width: 3
// specifying 'color' is also possible here
}
},
highlight: true,
tooltip: {
trackMouse: true,
renderer: function(storeItem, item) {
this.setHtml(storeItem.get('COUNTY') + ': ' + storeItem.get('AMOUNT') + '%');
}
}
}]
}];
this.callParent();
}
});
在浏览器中请求