vue3+ts 画echarts环形图表,vue-echarts是6.5.5版本
时间: 2023-08-16 19:26:27 浏览: 58
好的,下面是使用 Vue3 和 TypeScript 画 echarts 环形图表的步骤:
1. 安装 `vue-echarts`:
```bash
npm install vue-echarts echarts -S
```
2. 在 `main.ts` 中引入并注册 `vue-echarts`:
```typescript
import { createApp } from 'vue'
import App from './App.vue'
import ECharts from 'vue-echarts'
// 全局注册组件
createApp(App).component('v-chart', ECharts).mount('#app')
```
3. 在组件中使用 `v-chart` 组件,并传入相应的参数:
```html
<template>
<div>
<v-chart :options="options"></v-chart>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import * as echarts from 'echarts'
export default defineComponent({
data() {
return {
options: {
title: {
text: '示例图表',
left: 'center'
},
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b}: {c} ({d}%)'
},
legend: {
orient: 'vertical',
left: 10,
data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
},
series: [
{
name: '访问来源',
type: 'pie',
radius: ['50%', '70%'],
avoidLabelOverlap: false,
label: {
show: false,
position: 'center'
},
emphasis: {
label: {
show: true,
fontSize: '30',
fontWeight: 'bold'
}
},
labelLine: {
show: false
},
data: [
{ value: 335, name: '直接访问' },
{ value: 310, name: '邮件营销' },
{ value: 234, name: '联盟广告' },
{ value: 135, name: '视频广告' },
{ value: 1548, name: '搜索引擎' }
]
}
]
}
}
}
})
</script>
```
这样就可以在组件中画出一个简单的 echarts 环形图表了。如果需要更加复杂的图表,可以根据 echarts 文档自行配置 `options`。