溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

extjs圖形如何繪制之餅圖

發(fā)布時間:2021-05-18 10:56:10 來源:億速云 閱讀:212 作者:小新 欄目:web開發(fā)

這篇文章主要介紹了extjs圖形如何繪制之餅圖,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

具體如下:

這篇文章將介紹extjs中自帶的餅圖。

extjs圖形如何繪制之餅圖

代碼如下:

Ext.define('ChartPieTest', {
  extend: 'Ext.panel.Panel',
  autoScroll : true,
  initComponent: function () {
    var me = this;
    me.store = me.createStore();
    me.grid = me.getGridPanel();
    me.mainPanel = Ext.create('Ext.panel.Panel',{
      layout:'fit',
      items:[me.grid],
    });
 
    Ext.apply(me,{
      layout:'fit',
      items:[me.mainPanel]
    });
    me.callParent();
    me.mainPanel.down('chart').on('cellclick', function(grid, td, cellIndex, record, tr, rowIndex, e, eOpts) {
      me.onCellClick(cellIndex, record);
    });
  },
 
  getGridPanel:function(){
    var me = this;
    return {
      xtype:'chart',
      insetPadding: 40,
      animate : true,// 是否支持動態(tài)數(shù)據(jù)變化
      legend: {// 圖例
        position: "right",
        spacing: 12,
        padding: 5,
        font: {
          name: 'Tahoma',
          color: '#3366FF',
          size: 12,
          bold: true
        }
      },
      store:me.store,
      //axes:me.createAxes(),
      series:me.createSeries(),
    }
  },
  createStore: function () {
    var me = this;
    return Ext.create('Ext.data.JsonStore', {
      //從后端請求數(shù)據(jù)
     /* fields: [
        {name: 'id', mapping: 'id'},
        {name:'statTime',mapping:'statTime',type:'date',dateFormat:'time'},
        'activeCount', 'effectiveCount','effectiveProportion',
      ],
      proxy: {
        type: 'ajax',
        url: ctx+'/mvc/com/analyze/tblVwMonthUserStat',
        reader: {
          type: 'json',
          root: 'root',
          totalProperty: 'totalProperty'
        }
      },
      listeners: {
        'beforeload': function (store, operation, eOpts) {
          store.proxy.extraParams.selectYear = me.selectYear
        }
      },*/
     //自己模擬數(shù)據(jù)
      fields: ['name', 'data'],
      data: [
        { 'name': '中年人',  'data': 10 },
        { 'name': '嬰兒',  'data': 7 },
        { 'name': '老年人', 'data': 5 },
        { 'name': '小孩', 'data': 2 },
        { 'name': '青少年', 'data': 27 }
      ],
      autoLoad: true
    });
  },
  
  createSeries: function () {
    var me = this;
    var columns = [
      {
        type: 'pie',
        angleField: 'data',
        showInLegend: true,
        tips: {
          trackMouse: true,
          width: 140,
          height: 40,
          renderer: function(storeItem, item) {
            // calculate and display percentage on hover
            var total = 0;
            me.store.each(function(rec) {
              total += rec.get('data');
            });
            this.setTitle(storeItem.get('name') + ': ' + Math.round(storeItem.get('data') / total * 100) + '%');
          }
        },
        highlight: {
          segment: {
            margin: 5
          }
        },
        label: {
          field: 'name',
          display: 'rotate',
          contrast: true,
          font: '18px Arial'
        }
      },
 
    ];
    return columns;
  }
 
});

注:

1.上面中的createStore是創(chuàng)建餅圖所需要的數(shù)據(jù)的--store。

2.上面中的legend 顯示的右邊的圖例(表明哪塊代表什么數(shù)據(jù)),legend中的position屬性可以調(diào)節(jié)圖例的位置。其中有‘left'、‘right',‘bottom'、‘top'分別代表左右下上位置。

3.showInLegend是bool值,為false的時候不顯示上面的圖例。

4.tips這里是當(dāng)鼠標(biāo)放在餅圖上的時候顯示的提示性文字,其中的renderer方法中可設(shè)置提示哪些內(nèi)容。

5.label 設(shè)置餅圖上顯示文字的一些屬性。其中的display屬性決定文字在餅圖中位置,共有‘outside'、‘rotate'兩種方式,前者表示文字顯示在圖表的外邊,后者文字顯示在圖表的里邊。

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“extjs圖形如何繪制之餅圖”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI