in highcharts javascript file line number 1126 there is a function addEvent
/**
* Add an event listener
* @param {Object} el A HTML element or custom object
* @param {String} event The event type
* @param {Function} fn The event handler
*/
addEvent: function (el, event, fn) {
$(el).bind(event, fn);
},
I want to call my custom function instead of default function, and at the same time i don't want to change highcharts.js.
I want to assign it through external function, is there any way I can achieve this??
my new code will be
addEvent: function (el, event, fn) {
if(typeof(fn)=="string"){
try {
eval(fn);
} catch (e) {
if (e instanceof SyntaxError) {
console.log(e.message);
}
}
}
$(el).bind(event, fn);
}
Unfortuantely I don't know why wrapping addEvent doesn't work (while should!), but you can overwrite or wrap importEvents for point, to do similar thing (but only for points):
(function (H) {
H.wrap(H.Point.prototype, 'importEvents', function () {
if (!this.hasImportedEvents) {
var point = this,
options = H.merge(point.series.options.point, point.options),
events = options.events,
eventType;
point.events = events;
for (eventType in events) {
if (typeof events[eventType] == "string") {
try {
events[eventType] = eval(events[eventType]);
} catch (e) {
if (e instanceof SyntaxError) {
console.log(e.message);
}
}
}
H.addEvent(point, eventType, events[eventType]);
this.hasImportedEvents = true;
}
}
});
}(Highcharts));
Demo: http://jsfiddle.net/cXS5u/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With