代码拉取完成,页面将自动刷新
同步操作将从 han.yuan/ssr-echarts 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
const {createCanvas} = require('canvas')
const echarts = require('echarts')
// 引入主题
require('echarts-themes-js/src/chalk')
require('echarts-themes-js/src/essos')
require('echarts-themes-js/src/halloween')
require('echarts-themes-js/src/infographic')
require('echarts-themes-js/src/macarons')
require('echarts-themes-js/src/purple-passion')
require('echarts-themes-js/src/roma')
require('echarts-themes-js/src/romantic')
require('echarts-themes-js/src/shine')
require('echarts-themes-js/src/vintage')
require('echarts-themes-js/src/walden')
require('echarts-themes-js/src/westeros')
require('echarts-themes-js/src/wonderland')
// 生成图片
function generateImage(options, width, height, theme) {
console.log("GENERATE IMAGE")
console.log(`WIDTH: ${width}`)
console.log(`HEIGHT: ${height}`)
console.log(`THEME: ${theme}`)
console.log(`OPTIONS: ${JSON.stringify(options)}`)
const canvas = createCanvas(width, height)
const ctx = canvas.getContext('2d')
ctx.font = '12px'
echarts.setCanvasCreator(() => canvas)
const chart = echarts.init(canvas, theme)
options.animation = false
chart.setOption(options)
return chart.getDom().toBuffer()
}
const express = require('express')
const app = express()
app.use(express.json())
const imgController = (req, res) => {
console.log("RECV REQ")
let options = req.query.options || req.body
if (typeof options === 'string') {
options = JSON.parse(options)
}
let width = parseInt(req.query.width || options.width || 1024)
let height = parseInt(req.query.height || options.height || 768)
let theme = req.query.theme || options.theme || 'dark'
res.header("Content-Type", "image/png")
res.send(generateImage(options, width, height, theme))
}
app.post('/', imgController)
app.get('/', imgController)
const PORT = process.env.PORT || 3000
app.listen(PORT)
console.log("echarts started port:" + PORT)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。