PDA

View Full Version : Chart not working as module inside of namespace



yerajeff
22 Jun 2010, 8:58 AM
I have a pie chart that works fine when I run it like this:


Ext.namespace('APP');
Ext.chart.Chart.CHART_URL = '../../resources/charts.swf';

Ext.onReady(function(){


var chartstore = new Ext.data.JsonStore({
proxy: new Ext.data.HttpProxy({
url: 'groupcontacts.php', //url to data object (server side script)
method: 'POST'
}),
baseParams:{task: "readChart"},
fields:['group_name', 'total_contacts'],
root:'data',
autoLoad:true
});

// more complex with a custom look
new Ext.Panel({
title: 'Total Contacts By Group',
frame:true,
renderTo: 'chart-groups',
width:800,
height:300,
layout:'fit',
items: {
store: chartstore,
xtype: 'piechart',
dataField: 'total_contacts',
categoryField: 'group_name',
//extra styles get applied to the chart defaults
extraStyle:
{
legend:
{
display: 'bottom',
padding: 5,
font:
{
family: 'Tahoma',
size: 13
}
}
}
}
});
});However, another module (grid) needs to communicate with the chart and reload the chart's store. I tried to make the chart into a module so that this communication could happen, but when I do that the chart just stops working. Here is the code I'm using to make the chart into a module:



Ext.namespace('APP');
Ext.chart.Chart.CHART_URL = '../../resources/charts.swf';

APP.groupsChartModule = function(){

return {

chartinit : function(){

var chartstore = new Ext.data.JsonStore({
proxy: new Ext.data.HttpProxy({
url: 'groupcontacts.php',
method: 'POST'
}),
baseParams:{task: "readChart"},
fields:['group_name', 'total_contacts'],
root:'data',
autoLoad:true
});


new Ext.Panel({
title: 'Total Contacts By Group',
frame:true,
renderTo: 'chart-groups',
width:800,
height:300,
layout:'fit',
items: {
store: chartstore,
xtype: 'piechart',
dataField: 'total_contacts',
categoryField: 'group_name',
extraStyle:
{
legend:
{
display: 'bottom',
padding: 5,
font:
{
family: 'Tahoma',
size: 13
}
}
}
}
});

},//end of init method

}//end of return

}();
Ext.onReady(APP.groupsChartModule.chartinit, APP.groupsChartModule, true);Any ideas on why this would be happening? Thanks in advance!