【问题标题】:highcharts-export-server yAxis formatter does not workhighcharts-export-server yAxis 格式化程序不起作用
【发布时间】:2017-11-17 06:36:25
【问题描述】:

highcharts 可以设置 yAxis formatter 函数来改变 yAxis 格式,但是 使用 highcharts-export-server 生成图片,yAxis formatter 不起作用。

演示代码是这样的:

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

【问题讨论】:

    标签: highcharts


    【解决方案1】:

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

    但是,您可以像这样在callback 导出参数中使用formatter 函数:

    {
      "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']
      (...)
    

    注意整个函数是一个字符串。

    【讨论】:

    • 那个虫子刚刚杀死了我两天。这是一个非常讨厌的。
    • 假设 2021 年仍然如此?
    猜你喜欢
    • 1970-01-01
    • 2013-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多