yudao-dev/src/views/equipment/analysis/quality/components/lineChart.vue

209 lines
4.2 KiB
Vue
Raw Normal View History

2023-09-04 13:54:37 +08:00
<!--
filename: lineChart.vue
author: liubin
date: 2023-09-04 13:45:00
description:
-->
<template>
2023-09-04 14:35:13 +08:00
<div class="line-chart"></div>
2023-09-04 13:54:37 +08:00
</template>
<script>
2023-09-04 14:35:13 +08:00
import * as echarts from 'echarts';
2023-09-04 13:54:37 +08:00
export default {
name: 'LineChart',
components: {},
2023-09-19 17:06:19 +08:00
props: ['config', 'list'],
2023-09-04 13:54:37 +08:00
data() {
return {
2023-09-04 14:35:13 +08:00
chart: null,
};
2023-09-04 13:54:37 +08:00
},
2023-11-27 11:31:21 +08:00
watch: {
list: {
handler(listdata) {
this.setOption();
},
immediate: true,
deep: true,
},
},
2023-09-19 17:06:19 +08:00
computed: {
option() {
const opt = [];
this.list.map((eq) => {
2023-09-25 15:47:39 +08:00
/** [设备名, ok数量, 不ok数量, 加工数量, 合格率] */
opt.push([
eq.equipmentName,
eq.okQuantity,
eq.nokQuantity,
eq.totalQuantity,
2023-10-12 17:03:07 +08:00
eq.passRate?.toFixed(4),
2023-09-25 15:47:39 +08:00
]);
2023-09-19 17:06:19 +08:00
});
return {
2023-09-20 09:11:31 +08:00
color: ['#288AFF', '#8EF0AB'],
2023-09-19 17:06:19 +08:00
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow',
},
2023-09-27 16:53:27 +08:00
formatter: (params) => {
const name = params[0].name;
2023-11-27 11:31:21 +08:00
const goodRate = opt.find((item) => item[0] == name)[4] || '0';
2023-09-27 16:53:27 +08:00
return `
<h1 style="font-size: 18px; letter-spacing: 1px;">${
params[0].axisValue
} <small>${goodRate}%</small></h1>
<ul style="margin: 0; padding: 0; min-width: 128px;">
${params
.map(
(item, index) => `
<li style="list-style: none; display: flex; justify-content: space-between; align-items: center;">
<div>
2023-10-09 17:01:19 +08:00
<span style="display: inline-block; width: 10px; height: 10px; border-radius: 2px; background-color: ${item.color}; margin-right: 5px;"></span>
2023-09-27 16:53:27 +08:00
${item.seriesName}
</div>
${item.value}
</li>
`
)
.join('')}
</ul>
`;
},
2023-09-19 17:06:19 +08:00
},
legend: {
itemWidth: 12,
itemHeight: 12,
2023-09-25 15:47:39 +08:00
right: 0,
2023-09-19 17:06:19 +08:00
},
grid: {
left: '1%',
right: '1%',
top: '8%',
bottom: '3%',
containLabel: true,
},
// xAxis: [
// {
// type: 'category',
// data: ['设备1', '设备2', '设备3', '设备4', '设备5'],
// },
// ],
// yAxis: [
// {
// type: 'value',
// splitLine: {
// lineStyle: {
// color: '#0001',
// },
// },
// },
// ],
xAxis: {
type: 'category',
axisTick: { show: false },
2023-11-27 11:31:21 +08:00
axisLabel: {
rotate: 45,
},
2023-09-19 17:06:19 +08:00
data: opt.map((item) => item[0]),
},
yAxis: {
type: 'value',
splitLine: {
lineStyle: {
color: '#0001',
},
},
},
series: [
{
2023-10-09 17:01:19 +08:00
animation: false,
2023-09-20 09:11:31 +08:00
name: '合格数量',
2023-09-19 17:06:19 +08:00
type: 'bar',
barWidth: 20,
stack: 's',
2023-09-20 09:11:31 +08:00
data: opt.map((item) => item[1]),
2023-09-19 17:06:19 +08:00
},
{
2023-10-09 17:01:19 +08:00
animation: false,
2023-09-20 09:11:31 +08:00
name: '不合格数量',
2023-09-19 17:06:19 +08:00
type: 'bar',
barWidth: 20,
stack: 's',
2023-09-20 09:11:31 +08:00
data: opt.map((item) => item[2]),
2023-09-19 17:06:19 +08:00
},
2023-09-27 16:53:27 +08:00
// {
// name: '加工数量',
// type: 'bar',
// barWidth: 20,
// data: opt.map((item) => item[3]),
// },
// {
// name: '合格率',
// type: 'line',
// data: opt.map((item) => item[4]),
// },
2023-09-19 17:06:19 +08:00
],
};
},
},
2023-09-04 14:35:13 +08:00
mounted() {
2023-09-19 17:06:19 +08:00
console.log('[linechart] mounted');
2023-09-04 14:35:13 +08:00
this.init();
},
beforeDestroy() {
if (this.chart) {
this.chart.dispose();
}
2023-09-19 17:06:19 +08:00
console.log('[linechart] destroyed');
2023-09-04 14:35:13 +08:00
},
methods: {
init() {
if (!this.chart) this.chart = echarts.init(this.$el);
2023-09-19 17:06:19 +08:00
console.log('[linechart] initialized', this.$el);
this.$nextTick(() => {
this.setOption();
});
},
setOption() {
if (this.chart) this.chart.setOption(this.option);
console.log('[linechart] option settled');
2023-09-04 14:35:13 +08:00
},
2023-09-19 17:06:19 +08:00
// handleList(list) {
// /** 清空数据 */
// this.option.series[0].data.splice(0);
// this.option.series[1].data.splice(0);
// this.option.xAxis.data.splice(0);
// list.map((eq) => {
// this.option.xAxis.data.push(eq.equipmentName);
// this.option.series[0].data.push(eq.nokQuantity);
// this.option.series[1].data.push(eq.okQuantity);
// });
// this.setOption();
// // const pureList = list.map((eq) => ({
// // name: eq.equipmentName,
// // ok: eq.okQuantity,
// // nok: eq.nokQuantity,
// // }));
// },
2023-09-04 14:35:13 +08:00
},
2023-09-04 13:54:37 +08:00
};
</script>
<style scoped lang="scss">
.line-chart {
2023-09-04 14:35:13 +08:00
padding: 0 12px;
2023-09-19 17:06:19 +08:00
height: 1px;
flex: 1;
2023-09-04 13:54:37 +08:00
}
</style>