function generateLineImage (myTitle, myLegend, data) {
var options = {
title: {
text: myTitle,
left: 'center'
},
legend: {
bottom: 0,
data: myLegend
},
grid: {
left: '3%',
right: '4%',
bottom: '10%',
containLabel: true
},
xAxis: {
show: true,
axisLabel: {
rotate: 30
},
data: DIProject
},
yAxis: {
type: 'value'
},
series: [
{
name: myLegend[0],
type: 'line',
label: { show: true },
data: data.map(v => v[0])
},
{
name: myLegend[1],
type: 'line',
label: { show: true },
data: data.map(v => v[1])
},
{
name: myLegend[2],
type: 'line',
label: { show: true },
data: data.map(v => v[2])
},
{
name: myLegend[3],
type: 'line',
label: { show: true },
data: data.map(v => v[3])
},
]
}
const canvas = createCanvas(750, 350) // 750 320的canvas
const ctx = canvas.getContext('2d')
ctx.font = '12px'
echarts.setCanvasCreator(() => canvas) // 使用node-canvas
const chart = echarts.init(canvas)
chart.setOption(options) // 就是echarts的options
return `data:image/png;base64,${chart.getDom().toBuffer().toString('base64')}` // 返回base64图片
}
服务器端(node) nodemailer outlook邮箱 node-canvas echarts 服务器动态生成图表转成base64图片以邮件形式发送
最新推荐文章于 2023-03-16 15:43:51 发布