场景:服务端通过数据自动生成图表用于自动推送消息或邮件
代码示例
import echats from 'echarts-svg';
export async function generateChart({ options, width, height, align = 'left' }) {
const chart = echats.create({
fontSize: '12px',
});
const svg = await chart.render(options, {
width,
height,
align
});
return svg;
}
public async generateAlarmChartGroupByOwner() {
const data = await this.getWeekDataGroupByOwner();
const svg = await generateChart({
width: 527,
height: 400,
options: {
title: {
text: '告警责任人',
},
tooltip: {},
xAxis: {
type: 'value',
boundaryGap: [0, 0.01],
},
yAxis: {
data: data.map((item) => item.owner),
},
grid: {
left: '2%',
right: '4%',
bottom: '3%',
containLabel: true,
},
series: [
{
name: '告警数量',
type: 'bar',
data: data.map((item) => item.cnt),
},
],
},
});
return svg;
}