Guides

Server-Side Rendering

Learn about SSR empowered by Nuxt ECharts.
This page assumes you've already read the official ECharts Server-Side Rendering Guide. Read that first if you are new to ECharts SSR.

Nuxt ECharts not only provides <VChart> which renders the chart dynamically in the browser with full functionality, but also offers components rendering charts on the server side which we may need in some specific scenarios:

  • Reducing the FCP time and ensuring the chart is displayed immediately.
  • Reducing code volume while complex interaction is required.

Server-Side SVG Rendering

<VChartIsland> is a Nuxt server component which renders an SVG chart based on its props. When its props update, this will result in a network request that will update the rendered SVG in place. Since it is static, no ECharts code needs to be loaded on the client side.

Since server components are rendered 'outside' the Vue component tree and don't contain JS on the client side, they don't have access to provide/inject. Thus we provide <VChartServer>, a wrapper component of <VChartIsland> which can inject data provided by its ancestor components.

Client Hydration

Lazy-Loading Full ECharts

We can have all ECharts functionality while still displaying the chart on the screen in a blink of an eye. If ssr is turned on, <VChart> will use <VChartServer> to render an SVG chart on the server to quickly output the first screen chart, and then on the client once <VChart> mounted in the browser, the same chart will be rerendered to achieve functionality from ECharts core.

Lightweight Client Runtime

Sometimes we don't need complex interactions implemented by the above solution, we can use VChartLight which hydrates the SVG rendered by the server via ECharts lightweight client runtime to achieve simple interactions like clicking and mouse-moving. The advantage is that the client no longer needs to load hundreds of KBs of ECharts code, it only needs to load a less than 4KB lightweight runtime code.

Summary

In this module, we introduced several different components. Let's summarize their respective applicable scenarios:

ComponentRendering SolutionLoading VolumeLoss of Function and InteractionRecommended Scenario
VChart with ssr:trueServer-side SVG rendering plus client-side ECharts lazy loadingLargeCannot interact before lazy loading is completedThe first screen load time is sensitive, high demand for complete functionality and interaction, the chart is best not needed for interaction immediately after loading
VChartIslandServer-side SVG renderingSmallDoes not support legend toggle series display, does not support tooltips and other interactions with high real-time requirementsThe first screen load time is sensitive, low demand for complete functionality and interaction
VChartServerServer-side SVG renderingSmallThe same as above but able to inject contextual option provided by an ancestor componentThe same as above
VChartLightServer-side SVG rendering plus client-side lightweight runtimeSmallCannot implement interactions with high real-time requirementsThe first screen load time is sensitive, low demand for complete functionality and interaction, very strict requirements for code volume, not strict requirements for interaction real-time
We also provide an example of using Nitro server route to implement a Server-rendered ECharts with lightweight client runtime.