PDA

View Full Version : Charts - Legend - overriding click events



asulhyan
27 Jun 2013, 10:25 AM
Is there a cleaner way for adding click events on legends. Can it be disabled and then I can add click handler ? Wanted to avoid doing something like this and then adding my custom handler ?



Ext.each(
Ext.getCmp(‘chartCmpConversion’)
.legend.items, function(item) {
item.un(“mousedown”, item.events.mousedown.listeners[0].fn);
})

slemmon
30 Jun 2013, 4:43 PM
You may find the legenditem click handling not entirely straightforward. You can add click event listeners to the legend's items, but the legend items are rebuilt through the process of hiding and showing the chart series if I remember correctly.

asulhyan
30 Jun 2013, 5:25 PM
Thanks. Something like below adding in 'afterrender' didn't work. Though adding 'clearListeners()' instead of 'un' does work. Not sure what I am missing here if I want to just clear a particular listener.





afterrender: function() {
var self = this;
Ext.each(this.chart.legend.items, function(item) {
item.items[0].un("mousedown", item.items[0].events.mousedown.listeners[0].fn);
item.items[1].un("mousedown", item.items[1].events.mousedown.listeners[0].fn);
});
}






You may find the legenditem click handling not entirely straightforward. You can add click event listeners to the legend's items, but the legend items are rebuilt through the process of hiding and showing the chart series if I remember correctly.

unfixedai
9 Sep 2013, 5:31 AM
First, override onMouseDown for LegendIItem:


Ext.override(Ext.chart.LegendItem, { onMouseDown: function() {
this.callParent(arguments);
this.legend.chart.fireEvent('LegendItemClick', this.yFieldIndex);
}
});


then in chart definition put



me.addEvents( 'LegendItemClick'
);


and add Listener
listeners:
{
LegendItemClick: {
fn: function(index) {
alert(index);
}
}

}