chartExporter.export回调返回未定义

时间:2020-10-09 05:07:50

标签: javascript node.js highcharts

我在node.js中使用highcharts-export-server在后端创建图表并将其另存为PNG / JPEG。当我在本地Mac OS上运行时,具有以下配置的图表将保存到文件中。

当我在docker中运行时,针对相同的配置,chartExporter.export函数返回undefined。

以下是简单的饼图数据:

const chartData = {
    type: "png",
    options: {
      chart: {
        "type": "pie",
        "height": 800,
        "spacingLeft": 10,
        "spacingRight": 10,
        "width": 1000,
      },
      "colors": [
        "#009E6A",
        "#BF1919"
      ],
    "title": {
      "text": null
    },
    "subtitle": {
      "text": null
    },
    "plotOptions": {
      "pie": {
        "allowPointSelect": true,
        "cursor": "pointer",
        "dataLabels": {
          "enabled": true,
          "format": "<b>{point.name}</b>: {point.y}"
        },
        "size": "75%",
        "showInLegend": true
      }
    },
    "legend": {
      "align": "center",
      "verticalAlign": "bottom",
      "layout": "horizontal"
    },
    "series": [
      {
        "name": "Test1",
        "innerSize": "50%",
        "data": [
          {
            "name": "Apple",
            "y": 1
          },
          {
            "name": "Banana",
            "y": 1
          }
        ]
      }
    ]
  }
}

导出功能-未定义res

    try {
      chartExporter.export(chartData, function (err, res) {
        console.log('res ', res); // ------> is returned undefined in docker
        const imageb64 = res.data;
        
        fs.writeFileSync(outputFile, imageb64, 'base64', function(err) {
          if(err) {
            logger.error(err);
            return reject(err);
          }
        });
        logger.debug('Chart image saved locally');
        return resolve();
      });
    }
    catch(e) {
      logger.error('error in exporting chart :: ', e);
      return reject(e);
    }

0 个答案:

没有答案
相关问题