Код контроллера:
const fs = require('fs')
const exporter = require('highcharts-export-server')
class ChartsService {
async getCharts(chart, title, xAxis, yAxis, series) {
let chartOptions = {
chart: {
type: 'bar'
},
title: {
text: 'Historic World Population by Region'
},
subtitle: {
text: 'Source: Our Code World'
},
xAxis: {
categories: ['Africa', 'America', 'Asia', 'Europe', 'Oceania'],
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'Population (millions)',
align: 'high'
},
labels: {
overflow: 'justify'
}
},
tooltip: {
valueSuffix: ' millions'
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -40,
y: 80,
floating: true,
borderWidth: 1,
backgroundColor: '#FFFFFF',
shadow: true
},
credits: {
enabled: false
},
series: [{
name: 'Year 1800',
data: [107, 31, 635, 203, 2]
}, {
name: 'Year 1900',
data: [133, 156, 947, 408, 6]
}, {
name: 'Year 2000',
data: [814, 841, 3714, 727, 31]
}, {
name: 'Year 2016',
data: [1216, 1001, 4436, 738, 40]
}]
};
exporter.initPool()
let html = await new Promise((resolve, reject) => {
exporter.export({type: "png", options: chartOptions}, (err, res) => {
if (err) {
reject(err)
} else {
const img = `<div><img src="data:image/png;base64,${res.data}" /></div>`
resolve(img)
}
exporter.killPool()
})
})
return html
}
}
module.exports = new ChartsService()
ответом получаю
глобально highcharts-export-server ставил, лицензия true, build.js запускал.(