2013-07-31 19 views
1

請考慮堆疊條形圖的以下example。通過在系列中添加標籤配置,我可以在條上顯示每個字段(喜劇,動作,戲劇,驚悚片)的數量,但是我怎樣才能顯示字段名?標籤的渲染器配置屬性似乎沒有多大用處,因爲該函數只接收作爲參數的計數。ExtJS在圖表內顯示字段名稱

label:{ 
    display:'insideStart' , 
    field:[null, null, 'drama', 'thriller'], 
    renderer:function(item){ 
    //For this case, item will be an int value. Thus, not sure how useful it is 
    //as we cannot get the field name from it. 
    }   
} 

回答

1

實際上,renderer函數的傳遞範圍是a lot more arguments而不僅僅是值。這些參數與onPlaceLabel方法相同,在開始時增加了值,並且在那裏記錄更好。

我們已經獲得了該系列領域的index,事實上,我們的item參數中也有series。就這樣,我們就可以實現你想要什麼:

label: { 
    display:'insideStart' 
    ,field:[null, null, 'drama', 'thriller'] 
    ,renderer: function(value, label, storeItem, item, i, display, animate, index) { 
     var series = item.series, 
      titles = series.title; 
     return titles && titles[index] || series.yField[index]; 
    } 
} 

我想先拿到冠軍,因爲在現實生活中,我也不會顯示原始字段名用戶。爲了記錄,這裏是如何配置整個系列才能做到這一點。它不會出現在文檔中,用戶評論除外...

series: [{ 
    type: 'bar', 
    axis: 'bottom', 
    gutter: 80, 
    xField: 'year', 
    yField: ['comedy', 'action', 'drama', 'thriller'], 
    title: ['Comédie', 'Action', 'Drame', 'Thriller'], 
    stacked: true, 
    label: { 
     display:'insideStart' 
     ,field:[null, null, 'drama', 'thriller'] 
     ,renderer: function(value, label, storeItem, item, i, display, animate, index) { 
      var series = item.series, 
       titles = series.title; 
      return titles && titles[index] || item.yField; 
     } 
    } 
}] 
+0

除了值之外的所有參數都未在renderer函數中定義。 – user2548144

+0

你確定你使用的是Ext4.2嗎? – rixo

相關問題