【发布时间】:2018-05-12 05:47:11
【问题描述】:
我正在尝试使用 node.js 将 highchart 图形保存到图像 (.png) 文件中
curl -H "Content-Type: application/json" -X POST -d '{"infile":{"title": {"text": "Steep Chart"}, "xAxis": {"categories": [“一月”、“二月”、“三月”]}、“系列”:[{“数据”:[29.9、71.5、106.4]}]}}' 127.0.0.1:7801 -o mychart.png
使用上面的 curl,我可以得到图像。我正在尝试使用节点。
在此示例中,要将 highchart 图像保存到文件中,需要进行哪些更改才能将 .png 文件作为我的输出?
//Include the exporter module
const exporter = require('highcharts-export-server');
//Export settings
var exportSettings = {
fileName : 'myChart', // The name of the chart
file : 'myChart.png', // The name of the chart plus its extension
type : 'png',
options: {
title: {
text: 'My Chart'
},
xAxis: {
categories: ["Jan", "Feb", "Mar", "Apr", "Mar", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
},
series: [
{
type: 'line',
data: [1, 3, 2, 4]
},
{
type: 'line',
data: [5, 3, 4, 2]
}
]
}
};
//Set up a pool of PhantomJS workers
exporter.initPool();
//Perform an export
/*
Export settings corresponds to the available CLI arguments described
above.
*/
exporter.export(exportSettings, function (err, res) {
//The export result is now in res.
//If the output is not PDF or SVG, it will be base64 encoded (res.data).
//If the output is a PDF or SVG, it will contain a filename (res.filename).
console.log('res : ' + res.data + ' : ' + res.filename);
console.log('err : ' + err);
//Kill the pool when we're done with it, and exit the application
exporter.killPool();
process.exit(1);
});
【问题讨论】:
标签: node.js highcharts png