1

我正在尝试从 JSON 数据中动态设置“系列样式”为饼图。当“oneWeekStore”加载 JSON 数据时,我希望遍历每条记录的“颜色”并动态地 setSeriesStyles 到 PieChart。下面是片段。

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}
                                                                           }                                    }                                                             }                                     ]                               }

我的 JSON 数据如下所示:

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

非常感谢您的指导

4

1 回答 1

1

你有一个经典的竞争条件 - 你设置一个依赖于状态未知的组件的运动事件。

您设置的事件是数据存储的加载,当它完成加载时,它会尝试与面板交互,但此时我们不知道面板是否已经渲染。

你最好的选择是让其中一件事情发生在对另一件事情的反应中,例如:

1)加载商店

2)在加载事件触发时,创建面板

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

或者

1)创建面板(图表)

2)在面板的渲染事件上,加载商店(删除autoLoad:true)

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

希望有帮助。

于 2010-02-09T18:44:51.937 回答