我正在尝试在服务器中保存highcharts PNG文件。我正在使用ubuntu,phantomjs,highcharts,highcharts导出,jquery。
如果我在终端中运行此程序,它将正常工作:
phantomjs /home/save-piechart.js '[{"name":"Category A","y":13},{"name":"Category B","y":8},{"name":"Category C","y":5},{"name":"Category D","y":4},{"name":"Category E","y":2},{"name":"Category F","y":2},{"name":"Category G","y":1},{"name":"Category H","y":1}]' 'trial.png'
如果我在eclipse中运行代码,它也可以正常工作。但是,部署后它不起作用。
我从Java代码中调用的save-piechart.js是:
var system = require('system');
var page = require('webpage').create();
var fs = require('fs');
//load JS libraries
page.injectJs("jquery.min.js");
page.injectJs("highcharts.js");
page.injectJs("exporting.js");
//image properties
var image_path = '/home/report/chart-images/';
var raw_json = system.args[1];
var json = raw_json.replace(/_~/g, " ");
json = JSON.parse(json)
var image_filename = system.args[2];
//chart properties
var chart_args = {
width: 800,
height: 400,
jsondata: json
};
var svg = page.evaluate(function(opt){
$('body').prepend('<div id="container"></div>');
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
width: opt.width,
height: opt.height,
type : 'pie'
},
exporting: {
enabled: false
},
title: {
text: ''
},
xAxis: {
type : 'category',
crosshair : true
},
yAxis: {
min : 0
},
plotOptions: {
series: {
enableMouseTracking: false,
shadow: false,
animation: false
}
},
colors:[
'#C53B38',
'#9ABF49',
'#513F66',
'#35ADCD',
'#346DB0',
'#396C31',
'#F2D16D',
'#706B40',
'#465B48',
'#6B7179',
'#26C2B6',
'#546164',
'#FD7975',
'#F3D032',
'#768082',
'#BF8F8F',
'#594673',
'#6595BF',
'#9ABBD9',
'#B1A1C0',
'#E8DFC8',
'#2D5261',
'#8D9184',
'#345E7C',
'#0F7169',
'#C93823',
'#E9A423',
'#89B147',
'#A74C1D',
'#FDE778',
'#BCCED9',
'#4D8A1C',
'#F49443',
'#818D8E',
'#A64941',
'#00BEE8',
'#5F3F1A',
'#E6F7D2',
'#95DCE8',
'#FFFFFF'
],
credits : {
enabled : false
},
series: [{
data: opt.jsondata
}]
});
return chart.getSVG();
}, chart_args);
//save diagram as PNG
page.render(image_path + image_filename);
phantom.exit();
我的Java代码是:
String json_data = raw_json.replaceAll(" ", "_~");
Process process = Runtime.getRuntime().exec("phantomjs /home/save-piechart.js " + json_data + " " + image_filename);
BufferedInputStream bis = new BufferedInputStream(process.getInputStream());
int read = 0;
byte[] output = new byte[1024];
while ((read = bis.read(output)) != -1) {
logger.info("Running save-piechart: " + output[read]);
}
bis.close();
我使用以下步骤部署代码:
有什么想法吗?