template:
<div class="echartOne" id="mychartOne" :style="{ float: 'left', width: '50%', height: '57%' }"></div>
js:
//npm 安装后引入 echarts
import * as echarts from 'echarts';
//
mounted() {
this.makeUpEcharts(1, 40, 'mychartOne', '白词占比', 'rgb(119,193,241)')
this.makeUpEcharts(1, 20, 'mychartTwo', '黑词占比', 'rgb(236,100,92)')
},
//
methods: {
makeUpEcharts(el, makeUp_val, id, ratio, background) {
let color = ['#EAF1FF', '#73A0FA']; //圆环两色
let echartData = [{
value: makeUp_val,
name: ratio,
itemStyle: {
color: background,
},
label: {
show: true,
fontSize: '15',
fontWeight: 'bold',
// formatter: '{b}\n\n{d}%',
position: 'center',
color: 'rgb(162,162,162)',
},
},
{
value: 100 - makeUp_val,
name: '',
itemStyle: {
color: 'rgba(238,238,238)',
},
label: {
show: false,
fontSize: '16',
fontWeight: 'bold',
formatter: '{b}\n\n{d}%',
position: 'center'
},
},
];
var option = {
color: color,
series: [{
type: 'pie',
radius: ['60%', '90%'], //控制圆环大小
center: ['50%', '50%'], //控制圆环位置
data: echartData,
hoverAnimation: false,
itemStyle: {
normal: {
borderWidth: 2
}
},
label: {
show: true,
fontSize: '16',
fontWeight: 'bold',
formatter: '{b}\n\n{d}%',
position: 'center'
},
}]
};
let myChart = echarts.init(document.getElementById(id));
myChart.setOption(option)
},
}