3
votes

I am having difficulty having the export feature to work on my server. I have tried searching and there is not much I can get specifically. I have tried both features and the same error shows up each time. This is the error I am getting

./phantomjs highcharts-convert.js -infile test.js -outfile chart.png

ReferenceError: Can't find variable: $

ERROR: the options variable was not available, contains the infile an syntax error? see ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

contents of test.js are :

{ 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] }] };

I have tried putting it in JSON format but it doesn't seem to be working...

6

6 Answers

4
votes

I had the exact same error...

Make sure you have 3 important files in the same folder as highcharts-convert.js

  1. highcharts.js -or- highstock.js
  2. highcharts-more.js
  3. jquery.js

Then, update the file names at the top of highcharts-convert.js to match these file names and save it.

var config = {
        /* define locations of mandatory javascript files */
        HIGHCHARTS: 'highcharts.js',
        HIGHCHARTS_MORE: 'highcharts-more.js',
        JQUERY: 'jquery.js',
        TIMEOUT: 2000 /* 2 seconds timout for loading images */
    },

Now you should have no more errors (or at least a different one, ha)

3
votes

When I downloaded highcharts-convert.js it had a tiny typo in the config: instead of jquery-1.9.1.min.js it said jquery.1.9.1.min.js (note the . instead of a -)

Took me an hour of digging and experimenting to figure it out... Hope this can save others some time.

2
votes

I was getting a similar error. When I had downloaded the HighCharts package, I ended up with highcharts-convert.js containing:

HIGHCHARTS: 'highstock.js'

rather than

HIGHCHARTS: 'highcharts.js'

Once I changed that filename, the chart was generated without issue.

1
votes

There is an error in the jquery filename within highcharts-convert.js. The part that says JQUERY: 'jquery.1.9.1.min.js', should be jquery-1.9.1.min.js. Note the '-' instead of '.'.

Also if you are getting a bunch of errors other than ReferenceError: Can't find variable: $ make sure you comment out the file dependencies that you don't need in the top of highcharts-convert.js.

That was quite frustrating to figure out...

0
votes

In highcharts-convert.js you have to define paths for:

  • Highcharts library
  • jQuery library

Otherwise it won't work.

0
votes

Same issue here. I was invoking the command from shell_exec within PHP and Apache Web Server. The user that executed the command (www-data or apache) doesn't have read permissions on jquery.min.js so the execution fails (by the way apache was killed by phantomjs) and I had ReferenceError: Can't find variable: $ because jquery weren't included at all. Hope this helps