2015-04-03 77 views
0

這是關於ExtJs5 charts.I無法更改條形圖的標籤。如何更改Extjs5中條形圖的標籤?

代碼是如下:

Ext.create('Ext.chart.CartesianChart', { 
     store: { 
      fields: ['pet', 'households', 'total'], 
      data: [{ 
       pet: {name:'Cats'}, 
       households: 38, 
       total: 93 
      }] 
     }, 
     axes: [{ 
      type: 'numeric', 
      position: 'left' 
     }, { 
      type: 'category', 
      position: 'bottom' 
     }], 
     series: [{ 
      type: 'bar', 
      xField: 'pet', 
      yField: 'households', 
      label:{ 
       field:'pet', 
       renderer:function(pet){ 
        return 'Dear '+pet.name; 
       } 
      } 
     }] 
    }); 

您一定已經注意到了該領域的「寵物」是一個對象而不是字符串。 渲染器系列標籤返回我想要它的值,但標籤仍然是[object Object]!該類別下

回答

0

標籤(代碼中的x軸)是由「類」不低於series.Try代碼渲染:

{ 
    type: 'category', 
    position: 'bottom', 
    renderer:function(label){ 
    return label.name;//the var 'label' represents the pet object. 
    } 
} 

順便說一句,我發現了另一個問題。無論圖表商店中有多少款型號,只顯示第一個條形圖!