Vue-ECharts 6 迁移记录


Vue-ECharts 6 迁移记录

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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM