首先引入Echarts图,在项目中安装或者直接在线引入
封装代码如下:
<template>
<div id="main" style="width: 600px; height: 400px">
<span>fdfd</span>
</div>
</template>
<script>
export default {
props: {
number: {
type: [Number, String],
default: 0,
},
},
watch: {
number() {
this.init();
},
},
mounted() {
this.init();
},
methods: {
init() {
// 基于准备好的dom,初始化echarts实例
var myChart = echarts.init(document.getElementById("main"));
// 指定图表的配置项和数据
var option = {
tooltip: {
show: false
},
legend: {
show: false
},
graphic: [{ //环形图中间添加文字
type: 'text', //通过不同top值可以设置上下显示
left: 'center',
top: '48%'