yudao-dev/src/views/databoard/components/DefectChart.vue
2024-01-08 16:59:42 +08:00

197 lines
4.5 KiB
Vue

<template>
<div class="defect-chart"></div>
</template>
<script>
import * as echarts from 'echarts';
import resize from './../mixins/resize'
export default {
name: 'DefectChart',
mixins: [resize],
props: {
chartTime: ''
},
data() {
return {
chart: null,
tempData: []
}
},
computed: {
israCheckType() {
return this.$store.state.websocket.israCheckType
},
israDayStatistic() {
return this.$store.state.websocket.israDayStatistic
},
israWeekStatistic() {
return this.$store.state.websocket.israWeekStatistic
},
israMonthStatistic() {
return this.$store.state.websocket.israMonthStatistic
},
israYearStatistic() {
return this.$store.state.websocket.israYearStatistic
}
},
watch: {
israDayStatistic: {
handler(newVal, oldVal) {
if (this.chartTime === '日') {
this.tempData = this.israDayStatistic
this.updateChart()
}
}
},
israWeekStatistic: {
handler(newVal, oldVal) {
if (this.chartTime === '周') {
this.tempData = this.israWeekStatistic
this.updateChart()
}
}
},
israMonthStatistic: {
handler(newVal, oldVal) {
if (this.chartTime === '月') {
this.tempData = this.israMonthStatistic
this.updateChart()
}
}
},
israYearStatistic: {
handler(newVal, oldVal) {
if (this.chartTime === '年') {
this.tempData = this.israYearStatistic
this.updateChart()
}
}
}
},
mounted() {
this.$el.addEventListener('resize', () => {
console.log('resziing.....');
});
this.updateChart()
},
methods: {
updateChart() {
if (
this.chart !== null &&
this.chart !== '' &&
this.chart !== undefined
) {
this.chart.dispose()
}
this.chart = echarts.init(this.$el);
let xData = []
let seriesData = []
for (let i = 0;i < this.israCheckType.length; i++) {
let obj = {}
obj.type = 'bar'
obj.stack = 'all'
obj.emphasis = {
focus:"series"
}
obj.name = this.israCheckType[i]
obj.barWidth = 12
obj.data = []
for (let j = 0;j < this.tempData.length; j++) {
for (let k = 0; k < this.tempData[j].data.length; k++) {
if (this.israCheckType[i] === this.tempData[j].data[k].checkType) {
obj.data.push(this.tempData[j].data[k].checkNum)
}
}
}
seriesData.push(obj)
}
this.tempData && this.tempData.length > 0 && this.tempData.map(item => {
xData.push(item.name)
})
var option = {
color: ["#2760FF", "#8167F6", "#5B9BFF", "#99D66C", "#FFD160", "#FF8A40"],
grid: { top: 80, right: 12, bottom: 20, left: 48 },
legend: {
top: 10,
left: 80,
padding: 5,
itemWidth: 12,
itemHeight: 12,
itemGap: 12,
height: 12,
textStyle: {
color: "#DFF1FE",
fontSize: 12,
},
data:this.israCheckType,
},
xAxis: {
type: "category",
data: xData,
axisLabel: {
color: "#fffc",
fontSize: 12,
},
axisTick: { show: false },
axisLine: {
lineStyle: {
width: 1,
color: "#213259",
},
},
},
yAxis: {
name: "单位/个",
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: seriesData
};
option && this.chart.setOption(option)
}
}
}
</script>
<style scoped lang="scss">
.defect-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>