Overview
Apache ECharts supports server-side rendering (SSR) to generate charts on the server and send them to the client as SVG. This approach provides faster initial rendering, better SEO, and reduced client-side JavaScript processing. The SSR implementation is located in~/workspace/source/ssr/ and provides both server-side rendering capabilities and client-side hydration for interactivity.
Installation
The SSR package is available as part of the ECharts distribution:echarts/ssr (CommonJS).
Server-Side Rendering
Basic Node.js Example
Render a chart to SVG on the server:Express.js Integration
Serve rendered charts through an Express application:Client-Side Hydration
After server-side rendering, you can add interactivity on the client using the hydration API fromssr/client/src/index.ts.
Hydration API
The client module provides ahydrate function to attach event listeners to server-rendered SVG:
Client Hydration Example
Hydration Implementation Details
Fromssr/client/src/index.ts:42-90, the hydration system:
- Finds the SVG root in the container
- Attaches event listeners to the SVG element
- Reads metadata attributes from SVG elements:
ecmeta_ssr_type: Type of element (‘chart’ or ‘legend’)ecmeta_series_index: Series index for data elementsecmeta_data_index: Data point indexecmeta_silent: Whether element should ignore events
- Fires callbacks with structured event parameters
Complete SSR + Hydration Example
Server (Node.js/Express)
Advanced SSR Patterns
Dynamic Data from Database
Caching SSR Results
SSR Benefits and Limitations
Benefits
Faster Initial Render
Charts are rendered on the server, appearing immediately without client-side processing
Better SEO
Search engines can index chart content as SVG markup
Reduced Client Load
Less JavaScript processing on client devices, especially beneficial for mobile
No Flash of Unstyled Content
Charts appear styled from the first paint
Limitations
Best Practices
Next Steps
Performance
Optimize server rendering performance for large datasets
Accessibility
Ensure SSR charts are accessible with ARIA labels