これがコロンボによるものに基づいた私の解決策です。
このバージョンでは、軸を宣言しながらハンドラーを設定できます。さらに、ラベルインデックスを取得できCategory
、他のタイプの軸をクリックする必要がないため、軸にのみオーバーライドを適用します。
軸宣言:
...
axes: [{
type: 'Numeric',
position: 'bottom',
fields: ['field1', 'field2', 'field3', 'field4'],
title: 'Percentages',
grid: true
}, {
type: 'Category',
position: 'left',
fields: ['machineName'],
title: 'Machine Names',
handler: function(axis, i, label){
console.log('Label text: %o',label.text);
console.log('Label index: %o',i);
console.log('Axis: %o',axis);
}
}],
...
オーバーライド:
Ext.override(Ext.chart.axis.Category,{
getOrCreateLabel: function(i, text) {
var me = this,
labelGroup = me.labelGroup,
textLabel = labelGroup.getAt(i),
surface = me.chart.surface;
if (textLabel) {
if (text != textLabel.attr.text) {
textLabel.setAttributes(Ext.apply({
text: text
}, me.label), true);
textLabel._bbox = textLabel.getBBox();
}
}
else {
textLabel = surface.add(Ext.apply({
group: labelGroup,
type: 'text',
x: 0,
y: 0,
text: text
}, me.label));
surface.renderItem(textLabel);
textLabel._bbox = textLabel.getBBox();
// add event handler
if (me.label.handler && typeof(me.label.handler) == 'function') {
textLabel.on('click',Ext.pass(me.label.handler,[me, i]));
}
}
if (me.label.rotation) {
textLabel.setAttributes({
rotation: {
degrees: 0
}
}, true);
textLabel._ubbox = textLabel.getBBox();
textLabel.setAttributes(me.label, true);
} else {
textLabel._ubbox = textLabel._bbox;
}
return textLabel;
}
});
これはExtJS4.0.7で行われたことに注意してください