170 lines
3.8 KiB
Vue
170 lines
3.8 KiB
Vue
|
<template>
|
||
|
<div class="defect-class-chart"></div>
|
||
|
</template>
|
||
|
<script>
|
||
|
import * as echarts from 'echarts';
|
||
|
import resize from './../mixins/resize'
|
||
|
export default {
|
||
|
name: 'DefectClassChart',
|
||
|
mixins: [resize],
|
||
|
props: {
|
||
|
chartType: ''
|
||
|
},
|
||
|
data() {
|
||
|
return {
|
||
|
chart: null
|
||
|
}
|
||
|
},
|
||
|
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() {
|
||
|
if (
|
||
|
this.chart !== null &&
|
||
|
this.chart !== '' &&
|
||
|
this.chart !== undefined
|
||
|
) {
|
||
|
this.chart.dispose()
|
||
|
}
|
||
|
this.chart = echarts.init(this.$el);
|
||
|
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'],
|
||
|
grid: { top: 40, right: 12, bottom: 80, left: 60 },
|
||
|
// legend: {
|
||
|
// top: 10,
|
||
|
// left: 80,
|
||
|
// padding: 5,
|
||
|
// itemWidth: 12,
|
||
|
// itemHeight: 12,
|
||
|
// itemGap: 12,
|
||
|
// height: 12,
|
||
|
// textStyle: {
|
||
|
// color: "#DFF1FE",
|
||
|
// fontSize: 12,
|
||
|
// },
|
||
|
// data:['a','b','c','d','e'],
|
||
|
// },
|
||
|
xAxis: {
|
||
|
type: "category",
|
||
|
data: xData,
|
||
|
axisLabel: {
|
||
|
color: "#fffc",
|
||
|
fontSize: 12,
|
||
|
rotate: 45
|
||
|
},
|
||
|
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: [
|
||
|
{
|
||
|
data: yData,
|
||
|
type: 'bar',
|
||
|
barWidth: 12,
|
||
|
label: {
|
||
|
show: true,
|
||
|
position: 'top'
|
||
|
},
|
||
|
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>
|