yudao-init/src/views/produce/data/lineChart.vue

183 lines
4.3 KiB
Vue
Raw Normal View History

2024-04-17 16:17:07 +08:00
<!--
* @Author: zwq
* @Date: 2022-01-21 14:43:06
2024-05-22 16:28:47 +08:00
* @LastEditors: DY
2024-06-24 16:57:15 +08:00
* @LastEditTime: 2024-06-24 11:13:48
2024-04-17 16:17:07 +08:00
* @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'
2024-06-19 16:04:42 +08:00
import { factoryListabbr } from "@/utils/constants";
2024-04-17 16:17:07 +08:00
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,
2024-06-24 16:57:15 +08:00
default: '35vh'
2024-04-17 16:17:07 +08:00
},
legendPosition: {
type: String,
default: 'center'
},
showLegend: {
type: Boolean,
default: false
},
legendData: {
type: Array,
default: () => []
}
},
data() {
return {
chart: null
}
},
2024-05-22 16:28:47 +08:00
// mounted() {
// this.$nextTick(() => {
// this.initChart()
// })
// },
2024-04-17 16:17:07 +08:00
beforeDestroy() {
if (!this.chart) {
return
}
this.chart.dispose()
this.chart = null
},
methods: {
2024-05-22 16:28:47 +08:00
initChart(xAxis, seriesList) {
2024-06-19 16:04:42 +08:00
console.log('2', xAxis, seriesList)
if (xAxis.length === 0) {
this.chart.clear()
}
else {
this.chart = echarts.init(document.getElementById(this.id))
console.log(this.$parent);
this.chart.setOption({
2024-04-17 16:17:07 +08:00
title: {
text: '',
// subtext: 'Fake Data'
},
legend: {
right: '90px',
top: '0%',
icon: 'rect',
itemWidth: 10,
itemHeight: 10,
itemGap: 40,
2024-06-19 16:04:42 +08:00
formatter(name) {
return name.split('-')[0]
},
data: ['玻璃芯片-0', '标准组件-0', 'BIPV-0']
2024-04-17 16:17:07 +08:00
},
2024-06-19 16:04:42 +08:00
tooltip: {
trigger: 'axis',
formatter: function(params) {
let result = `
<div style="width: 270px; display: flex">
<div style="width: 150px">${params[0].name}</div>
<div style="width: 60px">${factoryListabbr[0]}</div>
<div style="width: 60px">${factoryListabbr[1]}</div>
</div>`
const newArray = params.map(p => {
return {
glass: p.seriesName.split('-')[0], // 玻璃类型
factoryName: factoryListabbr[p.seriesName.split('-')[1]], // 工厂名称
value: p.value,
name: p.name,
marker: p.marker
}
})
const analyzeList = Object.groupBy(newArray, (member) => member.glass)
for (let g in analyzeList) {
// date => 玻璃类型
let oneData = `<div style="width: 270px; display: flex">
<div style="width: 150px">${analyzeList[g][0].marker} ${g}</div>`
for (let fac of factoryListabbr) {
let goodNum = 0
for (let ana of analyzeList[g]) {
if (ana.factoryName === fac && ana.value !== 0) {
goodNum = ana.value
}
}
oneData += `<div style="width: 60px">${goodNum}</div>`
}
result = result + oneData + '</div>'
}
return result
}
},
grid: { top: 100, right: 90, bottom: 10, left: 10, containLabel: true },
2024-04-17 16:17:07 +08:00
calculable: true,
xAxis: [
{
type: 'category',
2024-06-24 16:57:15 +08:00
name: '日期',
data: xAxis,
axisLabel: {
rotate: 25
}
2024-04-17 16:17:07 +08:00
}
],
yAxis: [
{
2024-06-24 16:57:15 +08:00
type: 'value',
name: '单位:个'
2024-04-17 16:17:07 +08:00
}
],
grid: {
2024-06-24 16:57:15 +08:00
top: '10%',
2024-04-17 16:17:07 +08:00
left: "1%",
2024-06-24 16:57:15 +08:00
right: "5%",
bottom: "0%",
2024-04-17 16:17:07 +08:00
containLabel: true
},
2024-05-22 16:28:47 +08:00
series: seriesList
}, true)
2024-06-19 16:04:42 +08:00
}
2024-04-17 16:17:07 +08:00
}
}
}
</script>
<style scoped>
2024-06-19 16:04:42 +08:00
.chartTooltipSpan {
width: 50px;
background: #787878;
}
2024-04-17 16:17:07 +08:00
/* .reportChart {
position: absolute;
height: 100%;
width: 100%;
top: 10px;
} */
</style>