yudao-dev/src/views/databoard/components/DefectClassChart.vue

170 lines
3.9 KiB
Vue
Raw Normal View History

2024-01-04 16:37:14 +08:00
<template>
2024-01-11 13:44:38 +08:00
<div>
<NotMsg v-show="notMsg"/>
<div id="defectClassChart" class="defect-class-chart" style="width:600px;height:390px;" v-show='!notMsg'></div>
</div>
2024-01-04 16:37:14 +08:00
</template>
<script>
import * as echarts from 'echarts';
import resize from './../mixins/resize'
2024-01-11 13:44:38 +08:00
import NotMsg from './../components/NotMsg'
2024-01-04 16:37:14 +08:00
export default {
name: 'DefectClassChart',
mixins: [resize],
2024-01-11 13:44:38 +08:00
components:{ NotMsg },
2024-01-04 16:37:14 +08:00
props: {
chartType: ''
},
data() {
return {
2024-01-11 13:44:38 +08:00
chart: null,
notMsg:false
2024-01-04 16:37:14 +08:00
}
},
computed: {
israDayStatistic() {
return this.$store.state.websocket.israDayStatistic
}
},
watch:{
israDayStatistic: {
handler(newVal, oldVal) {
if (newVal === oldVal) {
return false
}
this.updateChart()
}
},
chartType: {// 监听类型变化,更新图
handler(newVal, oldVal) {
this.updateChart()
}
}
},
mounted() {
this.$el.addEventListener('resize', () => {
console.log('resziing.....');
});
this.updateChart()
},
methods: {
updateChart() {
2024-01-11 13:44:38 +08:00
if (!this.israDayStatistic || this.israDayStatistic.length == 0) {
this.notMsg = true
return
} else {
this.notMsg = false
}
2024-01-04 16:37:14 +08:00
if (
this.chart !== null &&
this.chart !== '' &&
this.chart !== undefined
) {
this.chart.dispose()
}
2024-01-11 13:44:38 +08:00
this.chart = echarts.init(document.getElementById('defectClassChart'));
2024-01-04 16:37:14 +08:00
let tempData = []
let xData = []
let yData = []
this.israDayStatistic && this.israDayStatistic.length > 0 && this.israDayStatistic.map(item => {
if (this.chartType === item.name) {
tempData = item.data
return
}
})
tempData.length > 0 && tempData.map(item => {
xData.push(item.checkType)
yData.push(item.checkNum)
})
var option = {
color: ['#2760FF','#5B9BFF','#FFD160','#8167F6', '#99D66C', '#FF8A40'],
2024-01-11 13:44:38 +08:00
grid: { top: 40, right: 12, bottom: 65, left: 70 },
2024-01-04 16:37:14 +08:00
xAxis: {
type: "category",
data: xData,
axisLabel: {
color: "#fffc",
fontSize: 12,
2024-01-11 13:44:38 +08:00
rotate: 25
2024-01-04 16:37:14 +08:00
},
axisTick: { show: false },
axisLine: {
lineStyle: {
width: 1,
color: "#213259",
},
},
},
yAxis: {
2024-01-12 09:45:36 +08:00
name: "单位/个",
2024-01-04 16:37:14 +08:00
nameTextStyle: {
color: "#fff",
fontSize: 10,
align: "right",
},
type: "value",
axisLabel: {
color: "#fff",
fontSize: 12,
formatter: "{value}",
},
axisLine: {
show: true,
lineStyle: {
color: "#213259",
},
},
splitLine: {
lineStyle: {
color: "#213259a0",
},
},
},
tooltip: {
trigger: "axis",
axisPointer: {
type: "shadow",
},
className: "defect-chart-tooltip"
},
series: [
{
data: yData,
type: 'bar',
barWidth: 12,
label: {
show: true,
2024-01-11 13:44:38 +08:00
position: 'top',
distance: 10,
color: "#fffc"
2024-01-04 16:37:14 +08:00
},
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#5CB7FF' },
{ offset: 1, color: '#364BFE' }
])
},
}
]
};
option && this.chart.setOption(option)
}
}
}
</script>
<style scoped lang="scss">
.defect-class-chart {
width: 100%;
height: 100%;
}
</style>
<style>
.defect-chart-tooltip {
background: #0a2b4f77 !important;
border: none !important;
backdrop-filter: blur(12px);
}
.defect-chart-tooltip * {
color: #fff !important;
}
</style>