magarisi magarisi - 4 months ago 151
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: {
categories:['Jan','Feb','Mar','Apr',
'May','Jun','Jul','Aug',
'Sep','Oct','Nov','Dec']
},
series:[
{
data:[29.9,71.5,106.4,129.2,
144.0,176.0,135.6,148.5,
216.4,194.1,95.6,54.4]
}]
},
callback: function(chart){
chart.renderer
.arc(200,150,100,50,-Math.PI,0)
.attr({fill:'#FCFFC5',stroke:'black','stroke-width':1})
.add();
},
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

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.

Comments