vue-echarts 已经支持 ECharts 5,同时支持 Vue.js 2/3

官方demo

Vue 2

import Vue from 'vue'
import ECharts from 'vue-echarts'
import { use } from 'echarts/core'
// 手动引入 ECharts 各模块来减小打包体积

import {
  CanvasRenderer
} from 'echarts/renderers'
import {
  BarChart
} from 'echarts/charts'
import {
  GridComponent,
  TooltipComponent
} from 'echarts/components'

use([
  CanvasRenderer,
  BarChart,
  GridComponent,
  TooltipComponent
]);

// 全局注册组件(也可以使用局部注册)
Vue.component('v-chart', ECharts)

new Vue(...)

!!! 需要引用 包 vue/composition-api npm i -D @vue/composition-api

旧版本

import ECharts from 'vue-echarts'

import 'echarts/lib/chart/bar'
import 'echarts/lib/component/tooltip'
import 'echarts/lib/component/markLine'

export default {
  components: {
    'v-chart': ECharts
  },

新版本

import VChart from 'vue-echarts'
import { use } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers'
import { BarChart } from 'echarts/charts'
import {
  GridComponent,
  TooltipComponent,
  MarkLineComponent
} from 'echarts/components'
use([
  CanvasRenderer,
  BarChart,
  GridComponent,
  TooltipComponent,
  MarkLineComponent
])

export default {
  components: {
    'v-chart': VChart
  },

总结

与之前相比多了个 GridComponent

// `cartesian` coordinate system. For some historical
// reasons, it is named as grid, for example:
// chart.setOption({
//     grid: {...},
//     xAxis: {...},
//     yAxis: {...},
//     series: [{...}]
// });
use(GridComponent);

引用
https://github.com/ecomfe/vue-echarts/blob/main/README.md
https://github.com/apache/echarts/blob/master/src/echarts.all.ts
https://echarts.apache.org/zh/api.html#echartsInstance.setOption

相关文章:

  • 2021-08-24
  • 2022-12-23
  • 2021-07-16
  • 2021-06-03
  • 2021-05-16
  • 2021-12-11
  • 2021-11-07
  • 2022-02-11
猜你喜欢
  • 2022-01-16
  • 2021-05-07
  • 2021-09-08
  • 2021-06-02
  • 2021-07-11
  • 2022-12-23
  • 2021-05-20
相关资源
相似解决方案