English 中文(简体)
How to apply seriesStyles to piechart in ExtJs dynamically
原标题:

Am trying to set seriesstyles to piechart dynamically from the JSON data. When the oneWeekStore loads the JSON data, I wish to iterate through the color of each record and setSeriesStyles dynamically to PieChart. Below is the snippet.

var oneWeekStore = new Ext.data.JsonStore({
        id: jsonStore ,
         fields: [ appCount , appName ],
         autoLoad: true,
         root:  rows ,
         proxy:storeProxy,
         baseParams:{
                    interval : oneWeek ,
                    fromDate :frmDt.getValue()        
         },
         listeners: {load: {
         fn:function(store,records,options) {
         /*I wish iterate through each record,fetch  color 
           and setSeriesStyles. I tried passing sample arrays 
           as paramater to setSeriesStyles like 

**colors= new Array( 0x08E3FE , 0x448991 , 0x054D56 );
Ext.getCmp( test12 ).setSeriesStyles(colors)**   

           But FF throws error "this.swf is undefined". Could 
           you please let me know  the right format to pass as
           parameter.      */   
                  }
    });


var panel = new Ext.Panel{
              id:  1week ,                                                        title: 1 week ,                                               
         items : [ 
                           { id: test12 ,
              xtype :  piechart , 
              store : oneWeekStore, 
              dataField :  appCount , 
              categoryField :  appName ,
              extraStyle : {
                                legend:{
                        display :  right ,
                        padding : 5,
                        spacing: 2, font :color:0x000000,family:
                                 Arial , size:9},
                        border:{size :1,color :0x999999},
                        background:{color: 0xd6e1cc}
                                                                           }                                    }                                                             }                                     ]                               }

My JSON data looks below:

{"success":true,"rows":[{"appCount":"9693814","appName":"GED","color":"0xFB5D0D"},{"appCount":"5731","appName":"SGEF"","color":"0xFFFF6B"}]}

Your guidance is highly appreciated

问题回答

You have a classic race condition there - your setting an event in motion that relies on a Component who s status is unknown.

The event your setting off is the loading of the data Store, when that has finished loading it is trying to interact with the Panel, but at that point we don t know if the Panel has been rendered yet.

Your best bet is to make one of those things happen in reaction to the other, for example:

1 ) load the store

2 ) on load event fired, create the panel

var oneWeekStore = new Ext.data.JsonStore({
     id: jsonStore ,
     ...,
     listeners: {
         load:function(store,records,options) {
              var panel = new Ext.Panel({
                  ...,
                  seriesStyles: colors,
                  ...
              });
         }
     }
});

or

1 ) create the panel (chart)

2 ) on render event of the panel, load the store (remove autoLoad:true)

var panel = new Ext.Panel({
    id:  1week ,
    ...,
    listeners: {
        render: function(pnl){
            oneWeekStore.load();
        }
    }
});

Hope that helps.





相关问题
ExtJS load form items/fields from database

I am using ExtJS 3 here. I would like to populate a formpanel from database with fields to be submitted. Basically, I don t know witch fields my form will have and I want to generate all formpanel ...

How to use Ext JS for role based application

I am planning to use Ext JS for a large application. The application s features are role based. When user login, they only see menu and screen features related to them. My server side technology will ...

Dynamically adding a TabPanel to a Panel Region

I have a Panel layout with a TreePanel in one region. A user clicks on an node in the tree and a TabPanel should be displayed in another region with information, editing tools etc. for that tree node....

How to embed Json result within Extjs Panel?

I have some issues with Json result and embed it within the html of the Extjs Panel. Here s that I have managed to get so far. myPanel is embedded within a mainPanel, and I have some shows/hide of ...

Ajax data update. Extjs

I need to keep certain data ( in a grid) up to date and was gonna do a poll to the server every 15 seocnds or so to get the data and refresh the grid, however it feels a bit dirty ( the grid will have ...

Better way to call superclass method in ExtJS

All the ExtJS documentation and examples I have read suggest calling superclass methods like this: MyApp.MyPanel = Ext.extend(Ext.Panel, { initComponent: function() { // do something MyPanel ...

Merged Headers in Ext JS Grid

Is it possible to have two headers in Ext JS grids? I have to show my grid as grouped data.. for example product types and products. In my case I need a grid like this: Field | Product Type A ...

热门标签