Sometimes, we don't want to change the entire way that a method works, just a part of it. In these cases, it would be fantastic if we could just wrap a method or a property by calling our code either before or after the desired method. This recipe will show how we can wrap one such method in Highcharts, drawGraph
, but a similar technique can be applied to wrap other methods.
To set up a basic page and install jQuery and Highcharts, refer to the Getting ready section of the Creating your first chart recipe from Chapter 1, Getting Started with Highcharts.
To get started, perform the following steps:
Create an immediate function that takes
Highcharts
as an argument, as shown in the following code:(function(H) { // Later code goes here }(Highcharts));
Within that function, call the
wrap
function and give it an object and method to wrap, as shown in the following code:(function(H) { H.wrap( H.Series.prototype, 'drawGraph...