new Vue({
el: "#app",
data() {
return {
riskLegendList: [1, 2, 3, 4], // 各等级预警数量
riskColor: ['#24d29b', '#69cde1', '#fdd27b', '#ff8c53'],
riskColorOpacity: ['rgba(36, 210, 155,0.2)', 'rgba(105, 205, 225,0.2)', 'rgba(253, 210, 123,0.2)','rgba(255, 140, 83,0.2)'],
}
},
created() {
},
mounted() {
this.initChart(this.riskLegendList[0], this.riskLegendList[1], this.riskLegendList[2], this.riskLegendList[3], this.riskLegendList.reduce((previousValue, currentItem) => previousValue + currentItem, 0));
},
methods: {
initChart(level4Count, level5Count, level6Count, level7Count, levelTotalCount) {
levelTotalCount = levelTotalCount === 0 ? 1 : levelTotalCount;
let dataStyle = {
normal: {
label: {
show: false
},
labelLine: {
show: false
},
shadowBlur: 40,
borderWidth: 10,
shadowColor: 'rgba(0, 0, 0, 0)' //边框阴影
}
};
let option = {
title: {
show: false,
},
legend: {
show: false
},
tooltip: {
trigger: 'item',
show: true,
formatter: "{b} : <br/>{d}% {c}",
padding: [8, 10], //内边距
extraCssText: 'box-shadow: 0 0 3px rgba(255, 255, 255, 0.1);', //添加阴影
},
backgroundColor: 'rgb(255,255,255,0)',
series: [{
name: 'Level7',
type: 'pie',
clockWise: false,
radius: [116, 130],
center: ['50%', '50%'],
itemStyle: dataStyle,
hoverAnimation: false,
startAngle: 90,
label: {
borderRadius: '10',
},
data: [{
value: level7Count,
name: '7级',
itemStyle: {
normal: {
color: this.riskColor[0]
}
}
},
{
value: levelTotalCount - level7Count,
name: '',
tooltip: {
show: false
},
itemStyle: {
normal: {
color: this.riskColorOpacity[0],
label: {
show: false
},
labelLine: {
show: false
}
},
emphasis: {
color: this.riskColorOpacity[0]
}
}
},
]
}, {
name: 'Level7',
type: 'pie',
clockWise: false,
radius: [116, 130],
center: ['50%', '50%'],
itemStyle: dataStyle,
hoverAnimation: false,
startAngle: 90,
label: {
borderRadius: '10',
},
data: [{
value: level7Count,
name: '7级',
itemStyle: {
normal: {
color: this.riskColor[0]
}
}
},
{
value: levelTotalCount - level7Count,
name: '',
tooltip: {
show: false
},
itemStyle: {
normal: {
color: 'transparent',
label: {
show: false
},
labelLine: {
show: false
}
},
emphasis: {
color: this.riskColorOpacity[0]
}
}
},
]
},
{
name: 'Level6',
type: 'pie',
clockWise: false,
radius: [86, 100], // 灰色线弧度
center: ['50%', '50%'],
itemStyle: dataStyle,
hoverAnimation: false,
startAngle: 90,
data: [{
value: level6Count,
name: '6级',
itemStyle: {
normal: {
color: this.riskColor[1]
}
}
},
{
value: levelTotalCount - level6Count,
name: '',
tooltip: {
show: false
},
itemStyle: {
normal: {
color: this.riskColorOpacity[1],
label: {
show: false
},
labelLine: {
show: false
}
},
emphasis: {
color: this.riskColorOpacity[1]
}
}
},
]
},
{
name: 'Level6',
type: 'pie',
clockWise: false,
radius: [86, 100],
center: ['50%', '50%'],
itemStyle: dataStyle,
hoverAnimation: false,
startAngle: 90,
data: [{
value: level6Count,
name: '6级',
itemStyle: {
normal: {
color: this.riskColor[1]
}
}
},
{
value: levelTotalCount - level6Count,
name: '',
tooltip: {
show: false
},
itemStyle: {
normal: {
color: 'transparent',
label: {
show: false
},
labelLine: {
show: false
}
},
emphasis: {
color: this.riskColorOpacity[1]
}
}
},
]
},
{
name: 'Level5',
type: 'pie',
clockWise: false,
radius: [56, 70],
center: ['50%', '50%'],
itemStyle: dataStyle,
hoverAnimation: false,
startAngle: 90,
data: [{
value: level5Count,
name: '5级',
itemStyle: {
normal: {
color: this.riskColor[2]
}
}
},
{
value: levelTotalCount - level5Count,
name: '',
tooltip: {
show: false
},
itemStyle: {
normal: {
color: this.riskColorOpacity[2],
label: {
show: false
},
labelLine: {
show: false
}
},
emphasis: {
color: this.riskColorOpacity[2]
}
}
},
]
},
{
name: 'Level5',
type: 'pie',
clockWise: false,
radius: [56, 70],
center: ['50%', '50%'],
itemStyle: dataStyle,
hoverAnimation: false,
startAngle: 90,
data: [{
value: level5Count,
name: '5级',
itemStyle: {
normal: {
color: this.riskColor[2]
}
}
},
{
value: levelTotalCount - level5Count,
name: '',
tooltip: {
show: false
},
itemStyle: {
normal: {
color: 'transparent',
label: {
show: false
},
labelLine: {
show: false
}
},
emphasis: {
color: this.riskColorOpacity[2]
}
}
},
]
},
{
name: 'Level4',
type: 'pie',
clockWise: false,
radius: [26, 40],
center: ['50%', '50%'],
itemStyle: dataStyle,
hoverAnimation: false,
startAngle: 90,
data: [{
value: level4Count,
name: '4级及以上',
itemStyle: {
normal: {
color: this.riskColor[3]
}
}
},
{
value: levelTotalCount - level4Count,
name: '',
tooltip: {
show: false
},
itemStyle: {
normal: {
color: this.riskColorOpacity[3],
label: {
show: false
},
labelLine: {
show: false
}
},
emphasis: {
color: this.riskColorOpacity[3]
}
}
},
]
},
{
name: 'Level4',
type: 'pie',
clockWise: false,
radius: [26, 40],
center: ['50%', '50%'],
itemStyle: dataStyle,
hoverAnimation: false,
startAngle: 90,
data: [{
value: level4Count,
name: '4级及以上',
itemStyle: {
normal: {
color: this.riskColor[3]
}
}
},
{
value: levelTotalCount - level4Count,
name: '',
tooltip: {
show: false
},
itemStyle: {
normal: {
color: 'transparent',
label: {
show: false
},
labelLine: {
show: false
}
},
emphasis: {
color: this.riskColorOpacity[3]
}
}
},
]
}
]
};
let chart = document.getElementById("chart");
echarts.init(chart).setOption(option);
}
}
})
Echarts 圆环 一类数据对应一环
最新推荐文章于 2024-09-07 09:00:00 发布