PDA

View Full Version : HELP: Issue with creating multiple store instances...



neurodon
13 Jun 2012, 9:51 AM
Hello,

I have an application which uses a single store across multiple views. It binds a 'chart' xtype to a store, which right now generates random data to graph.

Here is my code:



items: {
xtype: 'chart',
theme: 'Core',
style: 'background:#fff',
store: new Core.store.LiveChartStore({}),
animate: true,
shadow: true,
axes: [{...


This approach works fine in another part of my application (I use a gridview bound to a store with a backend PHP/AJAX proxy that generates random data).

This is my store code:



window.generateLiveData = function(n, floor){
var d = new Date();
var x = d.getUTCMilliseconds();
console.log("LiveData");
var data = [],
p = (Math.random() * 11) + 1,
i;

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

for (i = 0; i < (n || 12); i++) {
data.push({
name: Ext.Date.monthNames[i % 12].substring(0,3),
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))
});
}
return data;
};

Ext.define('Core.store.LiveChartStore', {
extend: 'Ext.data.Store',

fields: ['name', 'data1', 'data2', 'data3', 'data4', 'data5', 'data6', 'data7', 'data9', 'data9'],
data: this.generateLiveData(),
autoLoad:true,

initComponent: function() {
me.callParent(arguments);
}
});




The issue is that all of my charts (6 in total) use the same instance of the store, and therefore graph the same dataset.

What am I doing wrong?

scottmartin
6 Jul 2012, 11:14 AM
The issue is that all of my charts (6 in total) use the same instance of the store

I believe that is your answer ;) .. you will need to have different stores.

Scott.

skirtle
6 Jul 2012, 11:54 AM
It may not be the store that's shared. The way you've defined the store class the data will be the same for all instances. Try moving the data randomization into the creation config:


store: new Core.store.LiveChartStore({
data: generateLiveData()
}),

Alternatively you could try setting it in the store's constructor before the callParent call.

Incidentally, there's no such method as initComponent for a store.