{{target: renderer}}
Most of browser-side charting libraries use SVG or Canvas as their underlying renderer. In the scope of Apache EChartsTM, they are usually alternative, without critical differences. But in some environment and scenarios, they show notable differences in performance or functionality.
ECharts has been using Canvas as its renderer (use VML for IE8-) from the beginning. As of ECharts v3.8 we provide an SVG renderer (beta version) as another option. Either of them can be used by specifing parameter renderer as 'canvas'
or 'svg'
when initailizing a chart instance.
Both SVG and Canvas, which are very different rendering implementations, are supported in ECharts by leveraging the Canvas and SVG renderers offered by the zrender library.
Generally speaking, Canvas is suitable for cases where there is a large amount of graphical elements (usually due to a large amount of data points), like heatmap and lines or scatter plot with large data in geo or parallel coordinates. In addition, it supports some special visual effect not supported by SVG. However, in some other scenarios SVG has some critical advantages: it consumes less memory than Canvas (especially in mobile devices), and gives better performance in rendering. Moreover, it never blurs when zooming the viewport of the browser whereas Canvas may blur.
Below is a comparison of frame rate during the initial animation stage when rendering line, bar, pie charts with the Canvas renderer and the SVG renderer:
In the example above, the SVG renderer provides better FPS performance in mobile devices. In some other scenarios with large amounts of data or with certain kinds of user interaction, the SVG renderer is still not as good as the Canvas renderer in performance, but two options provide the ability to optimize the performance according to the requirements of each developer.
How to make a choice? These factors, hardware and software environment, data amount and functional requirements, should be considered.
Therefore feedback of experiences and usage scenarios are strongly welcomed, which will help improve the these renderers.
Notice: The features of rich text, shadow and texture have not been supported yet in the current beta version of the SVG renderer.
ECharts uses Canvas by default. If a user intends to use the SVG renderer, the module of the SVG renderer should be included in ECharts bundle.
import 'zrender/lib/svg/svg';
Then we can specify renderer by parameter:
// Use the Canvas renderer (default). var chart = echarts.init(containerDom, null, {renderer: 'canvas'}); // which is equal to: var chart = echarts.init(containerDom, null, {renderer: 'canvas'}); // Use the SVG renderer. var chart = echarts.init(containerDom, null, {renderer: 'svg'});