echarts-web
v1.0.1
Published
This project uses `Koa 3` with `@koa/router` for API routing and `koa-static` for serving a standalone viewer site.
Downloads
15
Readme
echarts-web
This project uses Koa 3 with @koa/router for API routing and koa-static for serving a standalone viewer site.
API endpoints:
POST /api/chartsGET /api/charts/:id
The returned viewerUrl points to a static frontend page:
/viewer/index.html?chartId=<id>
Install and start
npm install
echarts-web.cmdOptional environment variables:
PORT=4000 APP_BASE_URL=http://127.0.0.1:4000 npm startDefault chart data directory:
~/.echarts-web/chartsOptional override:
ECHARTS_WEB_HOME=/custom/path/.echarts-web npm startExample request
curl -X POST http://127.0.0.1:3000/api/charts \
-H "Content-Type: application/json" \
-d '{
"title": "Weekly Sales",
"option": {
"tooltip": {},
"xAxis": {
"type": "category",
"data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
},
"yAxis": {
"type": "value"
},
"series": [
{
"type": "bar",
"data": [120, 200, 150, 80, 70, 110, 130]
}
]
}
}'Example response:
{
"id": "b2e819a0-9dcf-4379-86db-f795116b870a",
"viewerUrl": "http://127.0.0.1:3000/viewer/index.html?chartId=b2e819a0-9dcf-4379-86db-f795116b870a",
"apiUrl": "http://127.0.0.1:3000/api/charts/b2e819a0-9dcf-4379-86db-f795116b870a"
}Notes
- Uploaded chart records are stored in
~/.echarts-web/charts/*.jsonby default. - The frontend viewer is bundled into
public/viewer. - The viewer reads
chartIdfrom the query string and then calls the backend API.
