theGreenCabbage
theGreenCabbage

Reputation: 4845

Highcharts plugin/extension that runs after the chart has loaded

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:

  1. Should I perform my value label hiding procedure within an existing prototype?

  2. 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

Answers (2)

morganfree
morganfree

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:

  1. Add a function as a callback to Chart.prototype

    Highcharts.Chart.prototype.callbacks.push(function (chart) {
      console.log('callback')
    })
    
  2. Add chart's load event

    Highcharts.addEvent(Highcharts.Chart, 'load', function () {
      console.log('load event')
    })
    

live example: http://jsfiddle.net/kyfbwjke/

Upvotes: 1

theGreenCabbage
theGreenCabbage

Reputation: 4845

The following:

H.wrap(H.Chart.prototype, 'onload', function (p) { ... }

Is the same as charts.events.load

Upvotes: 0

Related Questions