PDA

View Full Version : [Overridde]Ext.chart.Chart



atian25
29 Jul 2009, 4:56 PM
1.more js style code,no as-like
2.add some fn to filter data



Ext.override(Ext.chart.Chart,{
/**
* override the as-like code, and add some interface for filter data
*/
refresh : function(){
var dataProvider = [];
if(!this.series){
dataProvider.push({
type: this.type,
dataProvider: this.collectData(this.store)
});
}else{
var styleChanged = false;
var seriesCount = this.series.length;
for(var i = 0; i < seriesCount; i++){
var currentSeries = this.series[i];
//make a copy of the series definitions so that we aren't editing them directly.
var item = {};
Ext.apply(item,currentSeries,{
type:this.type,
queryFn:this.queryFn,
prepareData:this.prepareData,
collectData: this.collectData
});
//encode the style
if(currentSeries.style){
item.style = Ext.encode(currentSeries.style);
styleChanged = true;
}
//collect the data for this series
item.dataProvider = item.collectData(this.store);
dataProvider.push(item);
item=null;
}
}
this.swf.setDataProvider(dataProvider);
},

/**
* Function which can be overridden to provide custom formatting for each Record
* ^_^ some code in DataView
*/
prepareData:function(obj,index,record){
return obj;
},
/**
* filter some data for some series
*/
queryFn:function(record,id){
return true;
},
/**
* Use for each series, if u want to filter some data for some series.notify these is function queryFn
* ^_^ also from DataView,and make some changes.
*/
collectData:function(store){
var records = store.queryBy(this.queryFn).getRange();
var r = [];
for(var i = 0, len = records.length; i < len; i++){
r[r.length] = this.prepareData(records[i].data, i, records[i]);
}
return r;
},
/**
* add if
*/
setSeries : function(series){
this.series = series;
if(this.isInitialized){
this.refresh();
}
},
tz:''
});

galdaka
30 Jul 2009, 4:11 AM
Screenshot or live example?

Thanks and greetings,