尝试使用 highcharts-export-server 尝试在服务器端渲染甘特图,但根本无法获取要渲染的系列数据。
根据 the docs ,我尝试运行导出 via commandline和as a node module ,但我总是得到一个空图表,显示标题、副标题和系列名称,但没有实际数据。
所有基本折线图示例配置均有效,我可以通过浏览器使用 Highcharts.ganttChart
方法渲染图表,因此我相信它特定于导出的甘特图配置服务器,或与毫秒日期转换相关(正如您在屏幕截图中看到的,X 轴没有呈现为日期,而是简单的数字)。根据其他线程的建议,我在 node_modules/highcharts-export-server
中运行 build.js
,全局进行命令行尝试,并在本地项目进行 Node 模块尝试,确保启用 gantt 和 moment 库,但这也没有帮助。
包括下面我的选项 json。我无法找到专门针对导出服务器的甘特图配置示例,因此这是我插入它们的最佳尝试:
{
"title": {
"text": "Gantt PoC"
},
"subtitle": {
"text": "Timeline"
},
"series": [
{
"name": "Gantt Demo",
"type": "gantt",
"data": [
{
"name": "Demo Task 1",
"id": "demo_task_1",
"start": 1564113600000,
"end": 1564718400000
},
{
"name": "Demo Task 2",
"id": "demo_task_2",
"start": 1564113600000,
"end": 1564718400000
}
]
}
],
"xAxis": {
"min": 1563681600000,
"max": 1571803200000
}
}
如果我的配置有任何明显的错误,如果我错过了准备环境的任何关键步骤,或者您可能有任何建议让我排除故障,请告诉我。谢谢!
最佳答案
我还尝试使用甘特图生成图像,只是我尝试了您建议完美工作的构造函数,谢谢。
highcharts-export-server --infile gantt.json --outfile gantt.png --type png --constr ganttChart
实际上我也尝试过使用HTTP Server
,工作得很好。谢谢@pawel_d
const fs = require("fs");
const chartExporter = require('highcharts-export-server');
chartExporter.initPool();
const chartDetails = {
type: "png",
constr : 'ganttChart',
options: {
series: [{
data: [{
start: 1,
end: 10
}]
}]
}
};
chartExporter.export(chartDetails, (err, res) => {
// Get the image data (base64)
let imageb64 = res.data;
// Filename of the output
let outputFile = "bar.png";
// Save the image to file
fs.writeFileSync(outputFile, imageb64, "base64", function(err) {
if (err) console.log(err);
});
console.log("Saved image!");
chartExporter.killPool();
});
关于node.js - Highcharts 导出服务甘特图不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58719551/