189 lines
4.7 KiB
Vue
189 lines
4.7 KiB
Vue
<!--
|
|
* @Author: zwq
|
|
* @Date: 2022-01-21 14:43:06
|
|
* @LastEditors: DY
|
|
* @LastEditTime: 2024-07-16 18:41:27
|
|
* @Description:
|
|
-->
|
|
<template>
|
|
<!-- <div> -->
|
|
<!-- <div :id="id" :class="className" :style="{ height: '65%', width:width}" /> -->
|
|
<div :id="id" :class="className" :style="{ height: height, width: width }" />
|
|
<!-- </div> -->
|
|
</template>
|
|
|
|
<script>
|
|
import * as echarts from 'echarts'
|
|
import 'echarts/theme/macarons' // echarts theme
|
|
import resize from '@/mixins/resize'
|
|
import { factoryListabbr } from "@/utils/constants";
|
|
|
|
export default {
|
|
name: 'OverviewBar',
|
|
mixins: [resize],
|
|
props: {
|
|
id: {
|
|
type: String,
|
|
default: 'reportChart'
|
|
},
|
|
className: {
|
|
type: String,
|
|
default: 'reportChart'
|
|
},
|
|
width: {
|
|
type: String,
|
|
default: '100%'
|
|
},
|
|
beilv: {
|
|
type: Number,
|
|
default: 1
|
|
},
|
|
height: {
|
|
type: String,
|
|
default: '35vh'
|
|
},
|
|
legendPosition: {
|
|
type: String,
|
|
default: 'center'
|
|
},
|
|
showLegend: {
|
|
type: Boolean,
|
|
default: false
|
|
},
|
|
legendData: {
|
|
type: Array,
|
|
default: () => []
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
chart: null
|
|
}
|
|
},
|
|
// mounted() {
|
|
// this.$nextTick(() => {
|
|
// this.initChart()
|
|
// })
|
|
// },
|
|
beforeDestroy() {
|
|
if (!this.chart) {
|
|
return
|
|
}
|
|
this.chart.dispose()
|
|
this.chart = null
|
|
},
|
|
methods: {
|
|
initChart(xAxis, seriesList, facs) {
|
|
if (xAxis.length === 0) {
|
|
this.chart.clear()
|
|
}
|
|
else {
|
|
this.chart = echarts.init(document.getElementById(this.id))
|
|
console.log(this.$parent);
|
|
this.chart.setOption({
|
|
title: {
|
|
text: '',
|
|
// subtext: 'Fake Data'
|
|
},
|
|
legend: {
|
|
right: '90px',
|
|
top: '0%',
|
|
icon: 'rect',
|
|
itemWidth: 10,
|
|
itemHeight: 10,
|
|
itemGap: 40,
|
|
formatter(name) {
|
|
return ['玻璃芯片', '标准组件', 'BIPV'][name.split('-')[1]]
|
|
},
|
|
data: ['瑞昌-0', '瑞昌-1', '瑞昌-2']
|
|
},
|
|
tooltip: {
|
|
trigger: 'axis',
|
|
axisPointer: {
|
|
type: 'shadow',
|
|
color: "rgba(237,237,237,0.5)"
|
|
},
|
|
formatter(params) {
|
|
let str = ''
|
|
facs.forEach(ele => {
|
|
str += `<div style="width: 60px; text-align: right">${ factoryListabbr[ele] }</div>`
|
|
})
|
|
let result = `
|
|
<div style="width: 270px; display: flex">
|
|
<div style="width: 150px">${params[0].name}</div>
|
|
${ str }
|
|
</div>`
|
|
const analyzeArray = params.filter(p => p.seriesName !== '显示工厂').map(item => {
|
|
const obj = {
|
|
glass: ['玻璃芯片', '标准组件', 'BIPV'][item.seriesName.split('-')[1]], // 玻璃类型
|
|
factoryName: item.seriesName.split('-')[0], // 工厂名称
|
|
value: item.value,
|
|
name: item.name,
|
|
marker: item.marker,
|
|
color: item.color
|
|
}
|
|
return obj
|
|
})
|
|
const analyzeList = Object.groupBy(analyzeArray, (member) => member.glass)
|
|
for (let g in analyzeList) {
|
|
// date => 玻璃类型
|
|
let oneData = `<div style="width: 270px; display: flex">
|
|
<div style="width: 150px; display: flex; align-items: center">
|
|
<div style="background-color: ${analyzeList[g][0].color}; width: 10px; height: 10px; margin-right: 5px"></div>
|
|
<div>${g}</div></div>`
|
|
let goodNum = 0
|
|
for (let ana of analyzeList[g]) {
|
|
goodNum = ana.value
|
|
oneData += `<div style="width: 60px; text-align: right">${goodNum}</div>`
|
|
}
|
|
result = result + oneData + '</div>'
|
|
}
|
|
return result
|
|
}
|
|
},
|
|
grid: { top: 100, right: 90, bottom: 10, left: 10, containLabel: true },
|
|
calculable: true,
|
|
xAxis: [
|
|
{
|
|
type: 'category',
|
|
name: '日期',
|
|
data: xAxis,
|
|
axisLabel: {
|
|
rotate: 25
|
|
}
|
|
}
|
|
],
|
|
yAxis: [
|
|
{
|
|
type: 'value',
|
|
name: '单位:片'
|
|
}
|
|
],
|
|
grid: {
|
|
top: '10%',
|
|
left: "2%",
|
|
right: "5%",
|
|
bottom: "0%",
|
|
containLabel: true
|
|
},
|
|
series: seriesList
|
|
}, true)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.chartTooltipSpan {
|
|
width: 50px;
|
|
background: #787878;
|
|
}
|
|
/* .reportChart {
|
|
position: absolute;
|
|
height: 100%;
|
|
width: 100%;
|
|
top: 10px;
|
|
} */
|
|
</style>
|