magarisi magarisi - 1 year ago 275
Javascript Question

Highcharts and phantomjs error. Can't find variable Highcharts

I am trying to generate some serverside charts using Highcharts and phantomjs, but the following error keeps appearing:

Can't find variable Highcharts.

I know that there are similar questions here but none of them have helped me.
I am using Windows, with phantomjs 2.1.1, Highcharts 4.2.5

error image

Here is the options.js file:

infile: {
xAxis: {
callback: function(chart){
constr: "Chart",
outfile: "//tmp//chart.png"

And the highcharts-convert.js config options:

var config = {
HIGHCHARTS: 'highcharts.js',
JQUERY: 'jquery-1.9.1.min.js',
TIMEOUT: 5000 /* 5 seconds timout for loading images */

Has anyone solved this issue?

Answer Source

I have the exact same problem, although my command looks a bit different:

phantomjs  highcharts-convert.js -infile delete_this.json -outfile /home/max/BLA.png -width 300 -constr Chart -resources highcharts.js,jquery.js

as you see i included the needed files using the -resources option of phantom js, but i still get the 'Can't find variable: Highcharts' Error.

Maybe the resources part helps you?

EDIT: I solved my issue, and yours as well i think.

If you use the command like i described it, it doesn't give you the Highcharts error, BUT it breaks when trying to parse the resources. That is due to a grave error in the current version of the highcharts-convert.js script.

In line 682 they split the arguments, but they use an undefined parameter resources.

fileList = resources.split('\,');

You need to change that to:

fileList = params.resources.split('\,');

It works for me now, i hope it helps you.