Bonus-AI-LargeScreen/src/views/updateIDCard/pieIDResultCount.vue

145 lines
3.5 KiB
Vue
Raw Normal View History

2024-07-26 18:26:40 +08:00
<template>
2024-09-22 12:35:27 +08:00
<div class="pieBoxIDResultCount">
<div class="pieIDResultCount" ref="pieIDResultCount"></div>
<div class="pieTextBoxIDResultCount">
<div class='pieTextIDResultCount'>
调用正确率
</div>
<div class='pieTextIDResultCount'>
调用失败率
</div>
2024-07-26 18:26:40 +08:00
</div>
2024-09-22 12:35:27 +08:00
</div>
2024-07-26 18:26:40 +08:00
</template>
<script>
2024-09-22 12:35:27 +08:00
import {init, graphic} from 'echarts'
import {getPieData} from "@/api/updateIDCard/updateIDCard.js";
2024-07-29 17:49:56 +08:00
function roundToTwo(num) {
2024-09-22 12:35:27 +08:00
let tmp_num = num.toFixed(2).toString();
2024-07-29 17:49:56 +08:00
2024-09-22 12:35:27 +08:00
return tmp_num;
2024-07-29 17:49:56 +08:00
}
2024-07-26 18:26:40 +08:00
export default {
2024-09-22 12:35:27 +08:00
name: 'pieIDResultCount',
data() {
return {
pieOneChart: null,
pieEntityNameValue: {
pieright: '',
pieerror: ''
}
}
},
mounted() {
this.getPieDataID();
},
created() {
2024-10-08 16:28:17 +08:00
2024-09-22 12:35:27 +08:00
},
methods: {
getPieDataID() {
getPieData(1).then(res => {
try {
if (res.code == 200) {
this.pieEntityNameValue.pieright = (res.data.correctNu / res.data.totalNu * 100);
this.pieEntityNameValue.pieerror = (res.data.incorrectNu / res.data.totalNu * 100);
this.pieIDResultCount()
}
} catch (error) {
this.$modal.msgError("矩形图加载失败,请刷新页面或者请求管理员");
this.$modal.closeLoading();
}
}).catch(error => {
this.$modal.msgError("饼图加载失败,请刷新页面或者请求管理员");
this.$modal.closeLoading();
});
2024-07-29 17:49:56 +08:00
},
2024-09-22 12:35:27 +08:00
pieIDResultCount() {
let pieBlank = {
color: 'rgba(255,255,255,.8)',
};
let pieEntity = {
color: new graphic.LinearGradient(0, 0, 0, 1, [
{offset: 0, color: 'rgba(0, 255, 225, 0.3)'},
{offset: .5, color: 'rgba(100, 255, 100, 1)'},
{offset: 1, color: 'rgba(0, 255, 255, 0.7)'},
]),
};
let pieRadius = [30, 60];
let pieIDResultCount = init(this.$refs.pieIDResultCount);
console.log(this.pieEntityNameValue)
console.log(this.pieEntityNameValue.pieright)
let pieData = [
{name: 'pieright', value: this.pieEntityNameValue.pieright},
{name: 'pieerror', value: this.pieEntityNameValue.pieerror}
];
// console.log(pieData)
pieIDResultCount.setOption({
series: pieData.map((data, index) => ({
type: 'pie',
top: '15%',
center: [`${23 + 51 * index}%`, '50%'],
radius: pieRadius,
label: {
show: true,
formatter: function (params) {
if (params.name === 'blank')
return roundToTwo(100 - params.value) + "%"
else
return roundToTwo(params.value) + "%"//没有这个参数会出现数据漂移的现象如0.1+0.2=0.3
},
position: 'center',
fontSize: 15,
fontWeight: 'bold',
color: 'rgba(0, 255, 255, 0.7)'
},
data: [
{name: 'entity', value: data.value, itemStyle: pieEntity},
{name: 'blank', value: 100 - data.value, itemStyle: pieBlank}
]
}))
});
2024-07-26 18:26:40 +08:00
},
2024-09-22 12:35:27 +08:00
}
2024-07-26 18:26:40 +08:00
}
</script>
<style scoped>
.pieBoxIDResultCount {
2024-09-22 12:35:27 +08:00
height: 20rem;
width: 100%;
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
2024-07-26 18:26:40 +08:00
}
.pieIDResultCount {
2024-09-22 12:35:27 +08:00
flex: 10;
width: 100%;
2024-07-26 18:26:40 +08:00
}
.pieTextBoxIDResultCount {
2024-09-22 12:35:27 +08:00
flex: 2;
display: flex;
color: #fff;
width: 100%;
font-size: 1rem;
margin-left: 30%;
2024-07-26 18:26:40 +08:00
}
.pieTextIDResultCount {
2024-09-22 12:35:27 +08:00
flex: 1
2024-07-26 18:26:40 +08:00
}
2024-09-22 12:35:27 +08:00
</style>