vue echarts饼图
时间: 2023-06-14 17:04:30 浏览: 63
实现Vue Echarts饼图的步骤如下:
1. 安装Echarts
```bash
npm install echarts --save
```
2. 在Vue组件中引入Echarts
```javascript
import echarts from 'echarts'
```
3. 在Vue组件中引入Echarts的主题
```javascript
import 'echarts/theme/macarons.js'
```
4. 在Vue组件中添加Echarts
```vue
<template>
<div class="echarts-pie-chart" ref="echartsPieChart" style="width: 100%; height: 400px;"></div>
</template>
<script>
import echarts from 'echarts'
import 'echarts/theme/macarons.js'
export default {
name: 'EchartsPieChart',
mounted() {
this.initEchartsPieChart()
},
methods: {
initEchartsPieChart() {
const echartsPieChart = echarts.init(this.$refs.echartsPieChart, 'macarons')
const option = {
title: {
text: 'Echarts Pie Chart',
subtext: 'By Vue.js'
},
tooltip: {
trigger: 'item',
formatter: '{a} <br/> {b}: {c} ({d}%)'
},
legend: {
orient: 'vertical',
left: 10,
data: ['A', 'B', 'C', 'D', 'E']
},
series: [
{
name: 'Echarts Pie Chart',
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: 'A' },
{ value: 310, name: 'B' },
{ value: 234, name: 'C' },
{ value: 135, name: 'D' },
{ value: 548, name: 'E' }
]
}
]
}
echartsPieChart.setOption(option)
}
}
}
</script>
<style scoped>
.echarts-pie-chart {
margin: 0 auto;
}
</style>
```
5. 运行Vue项目,即可看到Echarts饼图。
注:以上代码仅供参考,具体实现方式根据实际需求进行调整。