-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs
32 lines (27 loc) · 805 Bytes
/
index.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import * as echarts from "npm:echarts";
Deno.serve(
/**
*
* @param {Request} req
*/
async (req) => {
if (req.method !== "POST")
return new Response("Method Not Allowed", { status: 405 });
const data = await req.json();
let chart = echarts.init(null, null, {
renderer: "svg", // must use SVG rendering mode
ssr: true, // enable SSR
width: data.width, // need to specify height and width
height: data.height,
});
chart.setOption(data);
const svgStr = chart.renderToSVGString();
chart.dispose();
chart = null;
return new Response(svgStr, {
headers: {
"Content-Type": "image/svg+xml",
},
});
}
);