vue-echarts

Vue ECharts

Vue ECharts

Vue.js component for Apache ECharts™.

npm version View demo 前往中文版

Still using Vue 2? Read v7 docs here →

Installation & Usage

npm

npm install echarts vue-echarts

Example

Demo → ```vue ```

[!IMPORTANT] We encourage manually importing components and charts from ECharts for smaller bundle size. We’ve built an import code generator to help you with that. You can just paste in your option code and we’ll generate the precise import code for you.

Try it →

But if you really want to import the whole ECharts bundle without having to import modules manually, just add this in your code:

import "echarts";

CDN

Drop <script> inside your HTML file and access the component via window.VueECharts.

Demo → ```html ``` ```js const app = Vue.createApp(...) // register globally (or you can do it locally) app.component('v-chart', VueECharts) ```

See more examples here.

Props

Events

You can bind events with Vue’s v-on directive.

<template>
  <v-chart :option="option" @highlight="handleHighlight" />
</template>

[!NOTE] Only the .once event modifier is supported as other modifiers are tightly coupled with the DOM event system.

Vue ECharts support the following events:

See supported events here →

Native DOM Events

As Vue ECharts binds events to the ECharts instance by default, there is some caveat when using native DOM events. You need to prefix the event name with native: to bind native DOM events.

<template>
  <v-chart @native:click="handleClick" />
</template>

Provide / Inject

Vue ECharts provides provide/inject API for theme, init-options, update-options and loading-options to help configuring contextual options. eg. for theme you can use the provide API like this:

Composition API ```js import { THEME_KEY } from "vue-echarts"; import { provide } from "vue"; provide(THEME_KEY, "dark"); // or provide a ref const theme = ref("dark"); provide(THEME_KEY, theme); // getter is also supported provide(THEME_KEY, () => theme.value); ```
Options API ```js import { THEME_KEY } from 'vue-echarts' import { computed } from 'vue' export default { { provide: { [THEME_KEY]: 'dark' } } } // Or make injections reactive export default { data() { return { theme: 'dark' } }, provide() { return { [THEME_KEY]: computed(() => this.theme) } } } ```

Methods

[!NOTE] The following ECharts instance methods aren’t exposed because their functionality is already provided by component props:

Slots

Vue ECharts allows you to define ECharts option’s tooltip.formatter and toolbox.feature.dataView.optionToContent callbacks via Vue slots instead of defining them in your option object. This simplifies custom HTMLElement rendering using familiar Vue templating.

Slot Naming Convention

Example mappings:

The slot props correspond to the first parameter of the callback function.

Usage ```vue <template #tooltip-xAxis="params">
X-Axis :
</template> <template #dataView="option"> <th v-for="(t, i) in option.dataset[0].source[0]" :key="i"> </th> <tr v-for="(row, i) in option.dataset[0].source.slice(1)" :key="i"> <td v-for="(v, i) in row.slice(1)" :key="i"></td> </tr>
</template> </v-chart> </template> ``` [Example →](https://vue-echarts.dev/#line)

[!NOTE] Slots take precedence over the corresponding callback defined in props.option.

Static Methods

Static methods can be accessed from echarts itself.

CSP: style-src or style-src-elem

If you are both enforcing a strict CSP that prevents inline <style> injection and targeting browsers that don’t support the CSSStyleSheet() constructor, you need to manually include vue-echarts/style.css.

Migration to v8

[!NOTE] Please make sure to read the upgrade guide for ECharts 6 as well.

The following breaking changes are introduced in vue-echarts@8:

Local development

pnpm i
pnpm dev

Open http://localhost:5173 to see the demo.

Notice

The Apache Software Foundation Apache ECharts, ECharts, Apache, the Apache feather, and the Apache ECharts project logo are either registered trademarks or trademarks of the Apache Software Foundation.