vue3中echarts饼图代码
时间: 2023-11-20 07:47:13 浏览: 90
以下是一个简单的饼图示例代码:
```
<template>
<div class="echarts-container" ref="echartsDom"></div>
</template>
<script>
import * as echarts from 'echarts';
export default {
data() {
return {
option: {
title: {
text: '饼图示例',
left: 'center'
},
tooltip: {
trigger: 'item',
formatter: '{a} <br/>{b}: {c} ({d}%)'
},
legend: {
orient: 'vertical',
left: 'left',
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: '搜索引擎' }
]
}
]
}
}
},
mounted() {
this.renderChart();
},
methods: {
renderChart() {
let echartsDom = this.$refs.echartsDom;
let myChart = echarts.init(echartsDom);
myChart.setOption(this.option);
}
}
}
</script>
<style scoped>
.echarts-container {
width: 100%;
height: 400px;
}
</style>
```
阅读全文