天天看點

ExtJs餅狀圖執行個體

直接上代碼

這是測試時候按照api寫的

Ext.define('AM.view.di.FurniturePoMain',{
    extend:'Ext.panel.Panel',
    id : 'di.FurniturePoView',
    alias :'widget.difurniturePoMain',
    title:'測試餅狀圖',
    layout: {
        type: 'border'
    },
    closable:true,
    initComponent : function() {
        var me = this;
        me.store = Ext.create('Ext.data.JsonStore', {
            fields: ['name', 'data'],
            data: [
                { 'name': '12小時',   'data':  },
                { 'name': '24小時',   'data':   },
                { 'name': '72小時', 'data':   },
                { 'name': '超72小時',  'data':   }
            ]
        });
        me.Panel =Ext.create('Ext.chart.Chart', {
            renderTo: Ext.getBody(),
            width: ,
            height: ,
            animate: true,
            store: me.store,
            theme: 'Base:gradients',
//          shadow: false,
            series: [{
                type: 'pie',
                angleField: 'data',
                showInLegend: true,
                tips: {
                    trackMouse: true,
                    width: ,
                    height: ,
                    renderer: function(storeItem, item) {
//                      alert(1);
                        var total = ;
                        me.store.each(function(rec) {
                            total += rec.get('data');
                        });
                        this.setTitle(storeItem.get('name') + ': ' +storeItem.get('data')+ ': '  + Math.round(storeItem.get('data') / total * ) + '%');
                    }
                },
                highlight: {
                    segment: {
                        margin: 
                    }
                },
                label: {
                    field: 'name',
                    display: 'rotate',
                    contrast: true,
                    font: '18px Arial'
                }
            }]
        });
        me.items = [me.Panel];
        me.callParent(arguments);
    }
});
           

下面是實際項目寫的,參照api Ext4.1

Ext.define('AM.view.di.StatisticsDeliveryEAnlysisPie', {
    extend : 'Ext.window.Window',
    alias : 'widget.statisticsDeliveryEAnlysisPie',
    title : '發貨效率分析餅狀圖',
    layout : {
        align : 'stretch',
        type : 'border'
    },
    autoShow : true,
    height : ,
    width : ,
    modal : true,
    buttonAlign : 'center',
    initComponent : function() {
        var me = this;
        var twelveCountSum = ;
        var dayCountSum = ;
        var twoDayCountSum = ;
        var threeDayCountSum = ;
        var limitDayCountSum = ;
        var items = Ext.getCmp("DeliveryEAnalysisMainPogrid").store.data.items;
        for(var i = ; i<items.length; i++){
            twelveCountSum += items[i].raw.twelveCount;
            dayCountSum += items[i].raw.dayCount;
            twoDayCountSum += items[i].raw.twoDayCount;
            threeDayCountSum += items[i].raw.threeDayCount;
            limitDayCountSum += items[i].raw.limitDayCount;
        }
        me.store = Ext.create('Ext.data.JsonStore', {
            fields: ['name', 'data'],
            data: [
                { 'name': '12小時',   'data': twelveCountSum },
                { 'name': '24小時',   'data':  dayCountSum },
                { 'name': '48小時', 'data':  twoDayCountSum },
                { 'name': '72小時', 'data':  threeDayCountSum },
                { 'name': '超72小時',  'data':  limitDayCountSum }
            ]
        });
        me.Panel =Ext.create('Ext.chart.Chart', {
            width: ,
            height: ,
            animate: true,
            store: me.store,
            shadow: true,
            insetPadding: ,
            legend: {
                position: 'right'
            },
            theme: 'Base:gradients',
            series: [{
                type: 'pie',
                angleField: 'data',
                showInLegend: true,
                tips: {
                    trackMouse: true,
                    width: ,
                    height: ,
                    renderer: function(storeItem, item) {
                        var total = ;
                        me.store.each(function(rec) {
                            total += rec.get('data');
                        });
                        this.setTitle(storeItem.get('name') + '</br> '+'單量:' + storeItem.get('data') + '</br> '+'百分比:' + Math.round(storeItem.get('data') / total * ) + '%');
                    }
                },
                highlight: {
                    segment: {
                        margin: 
                    }
                },
                label: {
//                  field: 'name',
//                  display: 'rotate',//如要在餅中顯示name  則開放此注釋
                    contrast: true,
                    font: '18px Arial'
                }
            }]
        });
        me.items = [me.Panel];
        me.callParent();
    }
});