📊📈 ECharts wrapper component for Vue 3, 2 and TypeScript
Features
Support for Vue 3 and 2;
Support auto resize;
Conform to the habits of Vue and ECharts users;
Provide pure function API, no side effects;
Lightweight encapsulation, easy to use;
Install
npm i -S echarts-for-vue
Usage
Vue 3
import{createApp,h}from'vue';import{plugin}from'echarts-for-vue';import*asechartsfrom'echarts';constapp=createApp({/*...*/});app.use(plugin,{ echarts, h });// use as a plugin
<template><EChartsref="chart" :option="option" /></template><script>import{createComponent}from'echarts-for-vue';import*asechartsfrom'echarts';import{h}from'vue';exportdefault{components: {ECharts: createComponent({ echarts, h }),// use as a component},data: ()=>({option: {/*...*/},}),methods: {doSomething(){this.$refs.chart.inst.getWidth();// call the method of ECharts instance},},}</script>
Vue 2
importVuefrom'vue';import{plugin}from'echarts-for-vue';import*asechartsfrom'echarts';Vue.use(plugin,{ echarts });// use as a plugin
<template><EChartsref="chart" :option="option" /></template><script>import{createComponent}from'echarts-for-vue';import*asechartsfrom'echarts';exportdefault{components: {ECharts: createComponent({ echarts }),// use as a component},data: ()=>({option: {/*...*/},}),methods: {doSomething(){this.$refs.chart.inst.getWidth();// call the method of ECharts instance},},}</script>