highcharts-export-server yAxis格式化程序不起作用

时间:2017-11-17 06:36:26

标签: highcharts

highcharts可以设置yAxis格式化程序功能来改变yAxis格式,但是 使用highcharts-export-server生成图像,yAxis格式化程序不起作用。

演示代码如下:

const exporter = require("highcharts-export-server");
const fs = require("fs");
const options = {
    "xAxis": {
        "categories": ['1', '2', '3', '4']
    },
    "yAxis": {
        title: {
            text: 'times'
        },
        plotLines: [
            {
                value: 0,
                width: 1,
                color: "#808080"
            }
        ],
        labels: {
            enabled: true,
            formatter: function () {
                return this.value * 100
            },
        },
    },
    "series": [{
        "data": [1, 3, 2, 4],
        "type": "line"
    }, {
        "data": [5, 3, 4, 2],
        "type": "line"
    }]
}

const exportSettings = {type: 'png',options}

//Set up a pool of PhantomJS workers
exporter.initPool();

//Perform an export
exporter.export(exportSettings, function (err, res) {
    var dataBuffer = new Buffer(res.data, 'base64');
    fs.writeFile("out.png", dataBuffer, function (err) {
        if (err) {
            console.log(err);
        } else {
            console.log("save success!");
        }
    });

    exporter.killPool();
});

任何人都有一些建议吗?谢谢!

结果:

demo result

1 个答案:

答案 0 :(得分:1)

与此问题相关的错误https://github.com/highcharts/node-export-server/issues/70

但是,您可以使用formatter导出参数中的callback函数,如下所示:

{
  "type": "Png",
  callback: `function(chart) {
    chart.yAxis[0].update({
      labels: {
        enabled: true,
        formatter: function() {
          return this.value * 100
        }

      }
    });
  }`,
  options: {
    "xAxis": {
      "categories": ['1', '2', '3', '4', '5']
  (...)

请注意,整个函数是一个String。