Home

Awesome

简体中文 | English

ECharts For Vue  Version

📊📈 ECharts wrapper component for Vue 3, 2 and TypeScript

Features

  1. Support for Vue 3 and 2;
  2. Support auto resize;
  3. Conform to the habits of Vue and ECharts users;
  4. Provide pure function API, no side effects;
  5. Lightweight encapsulation, easy to use;

Install

npm i -S echarts-for-vue

Usage

  1. Vue 3
import { createApp, h } from 'vue';
import { plugin } from 'echarts-for-vue';
import * as echarts from 'echarts';

const app = createApp({ /*...*/ });
app.use(plugin, { echarts, h });                        // use as a plugin
<template>
    <ECharts ref="chart" :option="option" />
</template>

<script>
    import { createComponent } from 'echarts-for-vue';
    import * as echarts from 'echarts';
    import { h } from 'vue';

    export default {
        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>
  1. Vue 2
import Vue from 'vue';
import { plugin } from 'echarts-for-vue';
import * as echarts from 'echarts';

Vue.use(plugin, { echarts });                           // use as a plugin
<template>
    <ECharts ref="chart" :option="option" />
</template>

<script>
    import { createComponent } from 'echarts-for-vue';
    import * as echarts from 'echarts';

    export default {
        components: {
            ECharts: createComponent({ echarts }),      // use as a component
        },
        data: () => ({
            option: { /*...*/ },
        }),
        methods: {
            doSomething() {
                this.$refs.chart.inst.getWidth();       // call the method of ECharts instance
            },
        },
    }
</script>
  1. <a href="test" target="_blank">More examples</a>
  2. <a href="https://ambit-tsai.github.io/echarts-for-vue/" target="_blank">Online demo</a>

Global API

DefinitionReturnDescription
createComponent(options: Options): objectComponent definition objectCreate a component
plugin(app: Vue, options: Options): voidThe installation method of plugin

Options

PropertyTypeDefaultOptionalDescription
echartstypeof echartsThe global object of ECharts library
hFunctionThe method createElement of Vue (Required for Vue 3)
ResizeObservertypeof ResizeObserverwindow.ResizeObserverWhen the global ResizeObserver doesn't exist, the <a href="https://github.com/que-etc/resize-observer-polyfill" target="_blank">polyfill</a> provides support
namestring"ECharts"The registered name of the component
deepWatchOptionbooleantruedeep watch prop "option"

Instance Properties

NameTypeReadOnlyDescription
instEChartsECharts instance

props

NameTypeDefaultReactiveDescription
initThemeobject | stringThe parameter theme of echarts.init method, <a href="https://echarts.apache.org/en/api.html#echarts.init" target="_blank">see</a>
initOptsobjectThe parameter opts of echarts.init method, <a href="https://echarts.apache.org/en/api.html#echarts.init" target="_blank">see</a>
loadingbooleanfalseShows loading animation
loadingTypestring"default"The parameter type of ECharts instance method showLoading, <a href="https://echarts.apache.org/en/api.html#echartsInstance.showLoading" target="_blank">see</a>
loadingOptsEChartsLoadingOptionThe parameter opts of ECharts instance method showLoading, <a href="https://echarts.apache.org/en/api.html#echartsInstance.showLoading" target="_blank">see</a>
optionEChartOptionThe parameter option of ECharts instance method setOption, <a href="https://echarts.apache.org/en/api.html#echartsInstance.setOption" target="_blank">see</a>
optionOptsEChartsOptionConfigThe parameter opts of ECharts instance method setOption, <a href="https://echarts.apache.org/en/api.html#echartsInstance.setOption" target="_blank">see</a>
eventsArguments[]An array element is the arguments of ECharts instance method on, <a href="https://echarts.apache.org/en/api.html#echartsInstance.on" target="_blank">see</a>
autoResizebooleantrueAuto resize

Beyond the props above, the remaining properties are passed to the root element of the component, such as style, class or onclick

Events

NameDescription
resizeTrigger when chart is resized

methods

DefinitionDescription
setOption(option: EChartOption, opts?: EChartsOptionConfig): voidCall the method setOption of ECharts instance, <a href="https://echarts.apache.org/en/api.html#echartsInstance.setOption" target="_blank">see</a>
resize(): voidResize chart (Based on the size of root element)
addResizeListener(): voidAdd "resize" listener
removeResizeListener(): voidRemove "resize" listener

Contact

  1. WeChat: cai_fanwei
  2. QQ: 854521460
  3. QQ Group: 663286147
  4. E-mail: ambit_tsai@qq.com