Reputation: 4845
I'm trying to move some of my custom Highcharts code that currently resides inside events.load
into a Highcharts extension so it's more modular and clean.
Here's a Fiddle of what I have right now.
As you can tell from the code, I change some value label properties when the chart has fully rendered, by calling chart.events.load
.
So from my understanding, using H.wrap
would allow me to override an existing prototype function and let me add code before or after it.
And this is where I am sort of confused:
Should I perform my value label hiding procedure within an existing prototype?
How can I convert the chart.events.load
code into an extension that (also) gets called after a chart is loaded?
I think I can use
H.wrap(H.Chart.prototype, 'onload', function (p) { ... }
But I am not entirely sure
Upvotes: 0
Views: 294
Reputation: 12472
I wouldn't use wrapp
unless I have to, e.g. when I would need to control when the wrapped function is called.
Other ways:
Add a function as a callback to Chart.prototype
Highcharts.Chart.prototype.callbacks.push(function (chart) {
console.log('callback')
})
Add chart's load
event
Highcharts.addEvent(Highcharts.Chart, 'load', function () {
console.log('load event')
})
live example: http://jsfiddle.net/kyfbwjke/
Upvotes: 1
Reputation: 4845
The following:
H.wrap(H.Chart.prototype, 'onload', function (p) { ... }
Is the same as charts.events.load
Upvotes: 0