gpt4 book ai didi

highcharts - 使用 highcharts-convert.js 设置格式化程序回调

转载 作者:行者123 更新时间:2023-12-01 22:04:53 25 4
gpt4 key购买 nike

我正在使用 highcharts-convert.js 在服务器端创建 PDF 图表。我想为柱形图( http://api.highcharts.com/highcharts#plotOptions.column.dataLabels )设置 dataLabel 格式化程序。由于这是一个函数,我无法将其写入作为 highcharts-convert.js 输入的输出 json 文件中。所以我假设我需要将它放在我的callback.js 中并像这样调用它:

highcharts-convert.js -infile infile.js -outfile outfile.pdf -width 1000 -callback callback.js

但是我无法在callback.js中设置格式化函数。我试过这个:

function( chart ) {
var labelFormatter = function(p) {
if (this.y == 0) {
return '';
}
else {
return this.y
}
};

chart.series.dataLabels.formatter = labelFormatter;
}

但这给了我这个错误:

TypeError: 'undefined' is not an object (evaluating 'chart.series.dataLabels.formatter = labelFormatter')

我尝试将格式化程序函数放在回调定义之外,但 highcharts-convert.js 不会接受。如何为 highcharts-convert.js 设置 dataLabel 格式化程序回调?

最佳答案

嗯,Highcharts 导出服务器的输入文件不必是真正的 JSON。一般来说,支持 JSON 中的函数。仅以此为例:

{"series": [{"data": [29.9, 71.5, 106.4], "dataLabels": { "enabled": true, "formatter":function(p) {if (this.y == 0) {return '';} else {return this.y+'a';}}}}]}

关于highcharts - 使用 highcharts-convert.js 设置格式化程序回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23203303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com