效果图如下 其他效果: 效果1:https://blog.csdn.net/weixin_41192581/article/details/104840199 效果2:https://www.cnblogs.com/myprogramer/p/12509764.html
注意: (1)最内层背景色、白色内框、进度条、外框,都是在 series 里设置 type为pie 的canvas (2)最内层背景色 和 背景色上的文字用 z: 2 和 zlevel: 100 提升层级 文字在graphic中设置 (3)阻止鼠标悬浮时区域弹出
hoverAnimation: false,
avoidLabelOverlap: false,
(4)取消鼠标高亮效果 方法一:silent: true , //取消鼠标移入高亮效果: 不响应和触发鼠标事件
silent: true,
方法二:将hover时的颜色与正常颜色设置为相同
data: [
{
value: 100,
itemStyle: {
normal: {
color: '#f5f5f5',
},
emphasis: { color: '#f5f5f5' },
},
},
],
(5)设置进度条圆角
borderRadius: ['20%', '50%'],
环形渐变: https://zhuanlan.zhihu.com/p/183893861
完整实现:
<template>
<div class="chartBox">
<div id="treeChart" :style="{ height: '242px' }"></div>
</div>
</template>
<script>
export default {
name: 'eCharts',
data() {
return {
value: 60,
}
},
mounted() {
this.showChart()
},
methods: {
showChart() {
var myChart = this.$echarts.init(document.getElementById('treeChart'))
var value = 200
var maxValue = 300
var option = {
legend: {
orient: 'vertical',
x: 'left',
},
graphic: [
{
type: 'text',
left: 'center',
top: '30%',
z: 2,
zlevel: 100,
style: {
text: '全省故障XX',
textAlign: 'center',
fill: '#333333',
fontSize: 12,
},
},
{
type: 'text',
left: 'center',
top: '36.5%',
z: 2,
zlevel: 100,
style: {
text: '解决率',
textAlign: 'center',
fill: '#333333',
fontSize: 12,
},
},
{
type: 'text',
left: 'center',
top: '45%',
z: 2,
zlevel: 100,
style: {
text: '67%',
textAlign: 'center',
fontWeight: 'bold',
fill: '#5393E7',
fontSize: 22,
},
},
{
type: 'text',
left: 'center',
top: '58%',
z: 2,
zlevel: 100,
style: {
text: '200 / 300',
textAlign: 'center',
fill: '#333333',
fontSize: 14,
},
},
{
type: 'text',
left: 'center',
top: '65.5%',
z: 2,
zlevel: 100,
style: {
text: '已解决 / 总数',
textAlign: 'center',
fill: '#333333',
fontSize: 12,
},
},
],
series: [
{
type: 'pie',
radius: [0, '60%'],
hoverAnimation: false,
labelLine: {
normal: {
show: false,
},
},
animation: false,
data: [
{
value: 100,
itemStyle: {
normal: {
color: '#f5f5f5',
},
emphasis: { color: '#f5f5f5' },
},
},
],
},
{
type: 'pie',
radius: ['60%', '61%'],
labelLine: {
normal: {
show: false,
},
},
hoverAnimation: false,
avoidLabelOverlap: false,
animationEasing: 'cubicOut',
data: [
{
value: this.value,
itemStyle: {
color: '#fff',
},
},
],
},
{
type: 'pie',
radius: ['62%', '73%'],
itemStyle: {
normal: {
color: '#6a5acd',
},
},
labelLine: {
normal: {
show: false,
},
},
hoverAnimation: false,
avoidLabelOverlap: false,
silent: true,
animationEasing: 'cubicOut',
data: [
{
value: value,
itemStyle: {
color: {
type: 'linear',
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0,
color: '#C9FFCB',
},
{
offset: 1,
color: '#2C87FF',
},
],
global: false,
},
borderRadius: ['20%', '50%'],
},
},
{
value: maxValue - value,
itemStyle: {
color: {
type: 'radial',
x: 1,
y: 1,
r: 1,
colorStops: [
{
offset: 0,
color: '#FCFCFC',
},
{
offset: 1,
color: '#F7F7F7',
},
],
global: false,
},
},
},
],
},
{
type: 'pie',
radius: ['73%', '83%'],
itemStyle: {
shadowBlur: 12,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.1)',
},
labelLine: {
normal: {
show: false,
},
},
hoverAnimation: false,
animationEasing: 'cubicOut',
data: [
{
value: this.value,
itemStyle: {
color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: '#F7F7F7',
},
{
offset: 1,
color: '#FCFCFC',
},
]),
},
},
],
},
],
}
myChart.setOption(option)
window.addEventListener('resize', function () {
myChart.resize()
})
},
},
}
</script>
<style lang="scss" scoped>
.chartBox {
width: 50%;
position: relative;
}
</style>
|