highcharts导出服务器js脚本错误代码

时间:2013-02-25 18:19:20

标签: export highcharts server-side highstock

当我尝试根据this tutorial在服务器端呈现图表时出现以下错误。

phantomjs highcharts-convert.js -infile options1.json -outfile chart1.png -scale 2.5 -width 300 -constr Chart -callback callback.js
SyntaxError: Parse error

SyntaxError: Parse error

Highcharts.options.parsed
Highcharts.callback.parsed
ReferenceError: Can't find variable: Highcharts

  phantomjs://webpage.evaluate():58
  phantomjs://webpage.evaluate():103
  phantomjs://webpage.evaluate():103
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...
loading images...

以下是同一目录中包含hightcharts-convert.js文件的文件。

 ls
callback.js            highcharts-more.js  highstock.js         options1.json
highcharts-convert.js  highcharts.js       jquery-1.8.2.min.js  readme.md

options1.json

的内容
{
        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.js的内容

function(chart) {
        chart.renderer.arc(200, 150, 100, 50, -Math.PI, 0).attr({
                fill : '#FCFFC5',
                stroke : 'black',
                'stroke-width' : 1
        }).add();
}

3 个答案:

答案 0 :(得分:4)

确保你的highstock.js是一个文本文件(不是二进制文件)! 文件http://code.highcharts.com/stock/highstock.js是gzip压缩的....

所以这里是一个详细的食谱:

在highcharts / exports-server / phantomjs中添加3个文件

cp js/highcharts.js exporting-server/phantomjs/
cp js/highcharts-more.js exporting-server/phantomjs/
curl http://code.highcharts.com/stock/highstock.js -o exporting-server/phantomjs/highstock.js.gz

现在解压缩文件:

gzip -d exporting-server/phantomjs/highstock.js.gz

如果你去文件夹:

cd exporting-server/phantomjs/

您可以检查md5校验和(当前版本2.3.5):

4a656e1918e259fbca5bb3bec6e3b945  highcharts-convert.js
3e2a05342b0d4d1b759dffffebc5f23f  highcharts-more.js
d6f1e284bc49d0502576e06d905274fd  highstock.js
cfa9051cc0b05eb519f1e16b2a6645d7  jquery-1.8.2.min.js
1fde128c0c2f8bf16fa1a4166e9b48c7  readme.md

我们可以制作包含文件的示例文件夹:

mkdir test

放入或创建两个输入文件:

第一个文件: callback.js

function(chart) {
        chart.renderer.arc(200, 150, 100, 50, -Math.PI, 0).attr({
                fill : '#FCFFC5',
                stroke : 'black',
                'stroke-width' : 1
        }).add();
}

第二档: infile.json

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

示例测试,这里是测试文件夹的命令行:

phantomjs  ../highcharts-convert.js -infile infile.json  -callback callback.js -outfile a.png -width 2400 -constr Chart -scale 1

控制台结果:

Highcharts.imagesLoaded:7a7dfcb5df73aaa51e67c9f38c5b07cb
done loading images

这就是这个伟大的图书馆。

答案 1 :(得分:0)

我认为这是正确的JSON:

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

答案 2 :(得分:0)

在我的情况下,highcharts.js缺少一个文件。

这件事可能有助于某人。