Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading Highcharts with require.js

I have been trying for some time with little success to be able to load highcharts as a require module. I was wondering if anyone had managed to get this working, or if they had any pointers to get me on the right track?

Thank you

like image 205
0x6C77 Avatar asked Nov 18 '11 16:11

0x6C77


2 Answers

With require.js 2.1.0+ a plugin is not necessary. You can include Highcharts with a shim:

require.config({
  paths: {
    require: "libs/require",
    jquery: "libs/jquery",
    highcharts: "libs/highcharts"
  },
  shim: {
    highcharts: {
      exports: "Highcharts",
      deps: ["jquery"]
    }
  } // end Shim Configuration
});
like image 193
Dan Weaver Avatar answered Sep 17 '22 17:09

Dan Weaver


I just got it to work as follows:

  1. Add this at the top:

    define(['jquery'], function (jQuery) {
    
  2. Add this at the very end:

    return window.Highcharts; });

This assumes you have jquery already defined, eg

require.config({
    paths: {
        'jquery': 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min'
     }
});

You can follow this general approach for most third party libraries. For example, I did this for jquery.tmpl.js and knockout.js.

like image 38
wachunga Avatar answered Sep 19 '22 17:09

wachunga