1

次の積み上げ棒グラフのを考えてみましょう。シリーズにラベル構成を追加することで、各フィールド (コメディ、アクション、ドラマ、スリラー) のカウントをバーに表示できますが、フィールド名も表示するにはどうすればよいでしょうか? 関数は引数としてカウントを受け取るだけなので、ラベルのレンダラー設定プロパティはあまり役に立たないようです。

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.
  }          
}
4

1 に答える 1

1

実際、レンダラー関数には、値だけでなく、さらに多くの引数が渡されます。これらの引数はメソッドと同じonPlaceLabelですが、先頭に値が追加されています。

indexシリーズにはフィールドの があり、実際のところseries、引数にも がありますitem。これで、私たちはあなたが望むものを達成することができます:

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;
        }
    }
}]
于 2013-07-31T22:27:00.793 に答える