Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 606
magarisi Avatar asked Jul 10 '16 16:07

magarisi


2 Answers

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.

like image 151
Max Uppenkamp Avatar answered Nov 13 '22 03:11

Max Uppenkamp


Thank you for the solution @max-uppenkamp. The Highcharts team should integrate this into their code without delay! EDIT: I see you have already notified them: https://github.com/highcharts/highcharts-export-server/issues/18

I note that a command-line as minimal as this will still work:

phantomjs highcharts-convert.js -infile options.json -outfile chart.png -resources highcharts.js

Also, I only need highcharts.js, highcharts-convert.js and options.js in my folder. Seems that I don't need highcharts-more or jquery.

NB. My options.json file looks like this:

{ chart: { type: 'bar' }, title: { text: 'Fruit Consumption' }, xAxis: { categories: ['Apples', 'Bananas', 'Oranges'] }, yAxis: { title: { text: 'Fruit eaten' } }, series: [{ name: 'Jane', data: [1, 0, 4] }, { name: 'John', data: [5, 7, 3] }] }

like image 41
Adam Avatar answered Nov 13 '22 05:11

Adam