2023-11-15 09:08:20 +08:00
|
|
|
<!--
|
|
|
|
* @Author: zhp
|
|
|
|
* @Date: 2023-09-21 09:06:28
|
2024-04-03 16:30:09 +08:00
|
|
|
* @LastEditTime: 2024-04-03 16:24:21
|
2023-11-15 09:08:20 +08:00
|
|
|
* @LastEditors: zhp
|
|
|
|
* @Description:
|
|
|
|
-->
|
|
|
|
<template>
|
2024-02-01 16:48:58 +08:00
|
|
|
<div style="height: 400px;">
|
|
|
|
<div :id="id" class="productChart" :style="{ height: '420px', width: width }" />
|
2023-11-15 09:08:20 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import * as echarts from 'echarts';
|
|
|
|
import 'echarts/theme/macarons' // echarts theme
|
|
|
|
import resize from './mixins/resize'
|
2024-02-01 16:48:58 +08:00
|
|
|
// import resize from './../mixins/resize'
|
2023-11-15 09:08:20 +08:00
|
|
|
export default {
|
|
|
|
name: 'OverviewBar',
|
|
|
|
mixins: [resize],
|
|
|
|
props: {
|
|
|
|
id: {
|
|
|
|
type: String,
|
|
|
|
default: 'linearBarChart'
|
|
|
|
},
|
|
|
|
className: {
|
|
|
|
type: String,
|
|
|
|
default: 'chart'
|
|
|
|
},
|
|
|
|
width: {
|
|
|
|
type: String,
|
|
|
|
default: '100%'
|
|
|
|
},
|
|
|
|
borderRadius: {
|
|
|
|
type: Array,
|
|
|
|
default: () => [9, 9, 0, 0]
|
|
|
|
},
|
|
|
|
beilv: {
|
|
|
|
type: Number,
|
|
|
|
default: 1
|
|
|
|
},
|
|
|
|
height: {
|
|
|
|
type: Number,
|
|
|
|
default: 200
|
|
|
|
},
|
|
|
|
showLegend: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
nameList: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
|
|
|
},
|
|
|
|
dataList: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
chart: null,
|
2023-12-29 09:00:00 +08:00
|
|
|
series: [{
|
|
|
|
type: 'bar',
|
|
|
|
data: [],
|
|
|
|
barWidth: 6
|
|
|
|
}]
|
2023-11-15 09:08:20 +08:00
|
|
|
}
|
|
|
|
},
|
2024-02-01 16:48:58 +08:00
|
|
|
// mounted() {
|
|
|
|
// console.log('mounted')
|
|
|
|
// console.log('borderRadius: ', this.borderRadius)
|
|
|
|
// // this.$nextTick(() => {
|
|
|
|
// // this.initChart()
|
|
|
|
// // })
|
|
|
|
// },
|
2023-11-15 09:08:20 +08:00
|
|
|
mounted() {
|
2024-02-01 16:48:58 +08:00
|
|
|
this.$el.addEventListener('resize', () => {
|
|
|
|
console.log('resziing.....');
|
|
|
|
});
|
2024-03-28 16:48:42 +08:00
|
|
|
// this.initChart()
|
2023-11-15 09:08:20 +08:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
if (!this.chart) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.chart.dispose()
|
|
|
|
this.chart = null
|
|
|
|
},
|
|
|
|
methods: {
|
2023-12-29 09:00:00 +08:00
|
|
|
initChart(nameList, passRateList, outputNumList) {
|
2024-01-16 16:09:52 +08:00
|
|
|
console.log(nameList, passRateList)
|
2023-12-29 09:00:00 +08:00
|
|
|
let series= [
|
|
|
|
{
|
|
|
|
name: '产线产量',
|
|
|
|
type: 'bar',
|
|
|
|
yAxisIndex: 1,
|
2024-01-09 16:25:12 +08:00
|
|
|
itemStyle: {
|
|
|
|
normal: {
|
|
|
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
|
|
{ offset: 0, color: '#9DD5FF' },
|
|
|
|
{ offset: 0.3, color: '#1295FF' }
|
|
|
|
]),
|
|
|
|
label: {
|
|
|
|
show: true, //开启显示
|
|
|
|
position: 'top', //在上方显示
|
|
|
|
textStyle: { //数值样式
|
2024-04-03 16:30:09 +08:00
|
|
|
color: 'rgba(255,255,255,0.5)', // 坐标值得具体的颜色
|
2024-03-29 16:56:21 +08:00
|
|
|
fontSize: 12,
|
|
|
|
fontWight:'bolder'
|
2024-01-09 16:25:12 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
2023-12-29 09:00:00 +08:00
|
|
|
// barBorderRadius: this.borderRadius
|
|
|
|
},
|
2024-03-28 15:36:39 +08:00
|
|
|
barWidth: 18,
|
2023-12-29 09:00:00 +08:00
|
|
|
data: outputNumList
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: '产线良品率',
|
2024-01-09 16:25:12 +08:00
|
|
|
symbol: 'circle', //变为实心圆
|
2023-12-29 09:00:00 +08:00
|
|
|
type: 'line',
|
|
|
|
yAxisIndex: 0,
|
|
|
|
areaStyle: {
|
|
|
|
opacity: 0.8,
|
|
|
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
|
|
{
|
|
|
|
offset: 0,
|
|
|
|
color: 'rgba(255, 209, 96, 0.18)'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
offset: 1,
|
|
|
|
color: 'rgba(255, 234, 153, 0)'
|
|
|
|
}
|
|
|
|
])
|
|
|
|
},
|
|
|
|
itemStyle: {
|
|
|
|
normal: {
|
|
|
|
color: 'rgba(255, 209, 96, 1)', //改变折线点的颜色
|
|
|
|
lineStyle: {
|
|
|
|
color: 'rgba(255, 209, 96, 1)' //改变折线颜色
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2024-01-30 18:13:57 +08:00
|
|
|
// data: passRateList
|
2024-03-29 16:56:21 +08:00
|
|
|
data: passRateList
|
2023-12-29 09:00:00 +08:00
|
|
|
}
|
|
|
|
]
|
2024-01-09 16:25:12 +08:00
|
|
|
// const colors = ['#5470C6', '#91CC75', '#EE6666']
|
2023-11-15 09:08:20 +08:00
|
|
|
this.chart = echarts.init(document.getElementById(this.id))
|
2024-03-27 17:02:44 +08:00
|
|
|
if (!nameList && !passRateList && !outputNumList) {
|
|
|
|
// 隐藏echarts图表
|
|
|
|
this.chart.clear(); // 清空图表
|
|
|
|
this.chart.setOption({ // 设置空的option
|
|
|
|
title: {
|
|
|
|
show: false
|
2023-11-15 09:08:20 +08:00
|
|
|
},
|
2024-03-27 17:02:44 +08:00
|
|
|
series: []
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// 显示echarts图表
|
|
|
|
this.chart.setOption({
|
|
|
|
// color: colors,
|
|
|
|
tooltip: {
|
|
|
|
trigger: 'axis',
|
|
|
|
axisPointer: {
|
|
|
|
type: 'cross'
|
|
|
|
}
|
2023-11-15 09:08:20 +08:00
|
|
|
},
|
2024-04-03 16:01:11 +08:00
|
|
|
grid: { top: 70, right: 20, bottom: 10, left: 10, containLabel: true },
|
|
|
|
// legend: {
|
|
|
|
// itemWidth: 10,
|
|
|
|
// itemHeight: 10,
|
|
|
|
// top: '2%',
|
|
|
|
// right: '30px',
|
|
|
|
// data: ['产线良品率', '产线产量'],
|
|
|
|
// textStyle: {
|
|
|
|
// fontSize: 12 * this.beilv,
|
|
|
|
// color: '#ced1d5',
|
|
|
|
// fontWight: 'bolder'
|
|
|
|
// }
|
|
|
|
// },
|
2024-03-27 17:02:44 +08:00
|
|
|
xAxis: {
|
2024-03-29 16:56:21 +08:00
|
|
|
axisTick: {
|
|
|
|
show: false
|
|
|
|
},
|
2024-03-27 17:02:44 +08:00
|
|
|
type: 'category',
|
2023-11-15 09:08:20 +08:00
|
|
|
axisLine: {
|
|
|
|
lineStyle: {
|
|
|
|
type: 'solid',
|
2024-03-13 14:54:35 +08:00
|
|
|
color: '#25528f',
|
2023-11-15 09:08:20 +08:00
|
|
|
width: '1' // 坐标线的宽度
|
|
|
|
}
|
|
|
|
},
|
2024-03-29 16:56:21 +08:00
|
|
|
textStyle: {
|
|
|
|
fontWight: 'bolder'
|
|
|
|
},
|
2023-11-15 09:08:20 +08:00
|
|
|
axisLabel: {
|
2024-03-29 16:56:21 +08:00
|
|
|
color: 'rgba(255,255,255,0.5)', // 坐标值得具体的颜色
|
2024-02-01 16:48:58 +08:00
|
|
|
fontSize: 12,
|
|
|
|
// formatter: '{value}'
|
2024-03-27 17:02:44 +08:00
|
|
|
// textStyle: {
|
|
|
|
// color: 'rgba(255,255,255,0.5)' // 坐标值得具体的颜色
|
2024-02-01 16:48:58 +08:00
|
|
|
// }
|
2023-11-15 09:08:20 +08:00
|
|
|
},
|
|
|
|
splitLine: {
|
|
|
|
lineStyle: {
|
2024-03-13 14:54:35 +08:00
|
|
|
color: '#25528f'
|
2023-11-15 09:08:20 +08:00
|
|
|
}
|
|
|
|
},
|
2024-03-27 17:02:44 +08:00
|
|
|
data: nameList
|
|
|
|
},
|
|
|
|
// yAxis: {
|
|
|
|
|
|
|
|
// },
|
|
|
|
yAxis: [
|
|
|
|
{
|
|
|
|
// min: function() { // 取最小值向下取整为最小刻度
|
|
|
|
// return 0
|
|
|
|
// },
|
|
|
|
// max: function(value) { // 取最大值向上取整为最大刻度
|
|
|
|
// return Math.ceil(value.max)
|
|
|
|
// },
|
|
|
|
scale: true,
|
|
|
|
type: 'value',
|
|
|
|
name: '良品率/%',
|
|
|
|
nameTextStyle: {// y轴上方单位的颜色
|
2024-03-29 16:56:21 +08:00
|
|
|
color: 'rgba(255,255,255,0.5)', // 坐标值得具体的颜色
|
2024-03-27 17:02:44 +08:00
|
|
|
align: "left",
|
2024-04-03 16:01:11 +08:00
|
|
|
padding: [0, 0, 0, 8]
|
2024-03-27 17:02:44 +08:00
|
|
|
},
|
|
|
|
position: 'right',
|
|
|
|
alignTicks: true,
|
|
|
|
axisLine: {
|
|
|
|
show: true,
|
|
|
|
lineStyle: {
|
|
|
|
// type: 'solid',
|
|
|
|
color: '#25528f',
|
|
|
|
// width: '1' // 坐标线的宽度
|
|
|
|
}
|
|
|
|
},
|
|
|
|
axisLabel: {
|
2024-03-29 16:56:21 +08:00
|
|
|
color: 'rgba(255,255,255,0.5)', // 坐标值得具体的颜色
|
2024-03-27 17:02:44 +08:00
|
|
|
fontSize: 12,
|
|
|
|
// formatter: '{value}'
|
|
|
|
formatter: '{value}%'
|
|
|
|
// }
|
|
|
|
},
|
|
|
|
splitLine: {
|
|
|
|
lineStyle: {
|
|
|
|
color: '#25528f'
|
|
|
|
}
|
2023-11-15 09:08:20 +08:00
|
|
|
}
|
2024-03-27 17:02:44 +08:00
|
|
|
// type: 'value'
|
|
|
|
// axisLine: {
|
|
|
|
// show: true,
|
|
|
|
// lineStyle: {
|
|
|
|
// color: colors[0]
|
|
|
|
// }
|
|
|
|
// },
|
2023-11-15 09:08:20 +08:00
|
|
|
},
|
2024-03-27 17:02:44 +08:00
|
|
|
{
|
|
|
|
// min: function() { // 取最小值向下取整为最小刻度
|
|
|
|
// return 0
|
|
|
|
// },
|
|
|
|
// max: function(value) { // 取最大值向上取整为最大刻度
|
|
|
|
// return Math.ceil(value.max)
|
|
|
|
// },
|
|
|
|
scale: true,
|
|
|
|
type: 'value',
|
|
|
|
name: '产量/片', // y轴上方的单位
|
|
|
|
nameTextStyle: {
|
2024-03-29 16:56:21 +08:00
|
|
|
color: 'rgba(255,255,255,0.5)', // 坐标值得具体的颜色
|
2024-03-27 17:02:44 +08:00
|
|
|
// fontSize: 10,
|
2024-04-03 16:01:11 +08:00
|
|
|
padding: [0, 4, 0, 0],
|
2024-03-27 17:02:44 +08:00
|
|
|
align: "right",
|
|
|
|
},
|
|
|
|
// position: 'left',
|
|
|
|
alignTicks: true,
|
|
|
|
axisLine: {
|
|
|
|
show: true,
|
|
|
|
lineStyle: {
|
|
|
|
// type: 'solid',
|
|
|
|
color: '#25528f', // 左边线的颜色
|
|
|
|
// width: '1' // 坐标线的宽度
|
|
|
|
}
|
|
|
|
},
|
|
|
|
axisLabel: {
|
|
|
|
// textStyle: {
|
|
|
|
// color: 'rgba(255,255,255,0.5)', // 坐标值得具体的颜色
|
2024-03-29 16:56:21 +08:00
|
|
|
color: 'rgba(255,255,255,0.5)', // 坐标值得具体的颜色
|
2024-03-27 17:02:44 +08:00
|
|
|
// show: true,
|
|
|
|
lineStyle: {
|
|
|
|
color: "#25528f",
|
|
|
|
},
|
|
|
|
// }
|
|
|
|
},
|
|
|
|
splitLine: {
|
|
|
|
lineStyle: {
|
|
|
|
color: '#25528f'
|
|
|
|
}
|
2023-11-15 09:08:20 +08:00
|
|
|
}
|
2024-03-27 17:02:44 +08:00
|
|
|
// type: 'value'
|
|
|
|
// axisLine: {
|
|
|
|
// show: true,
|
|
|
|
// lineStyle: {
|
|
|
|
// color: colors[1]
|
|
|
|
// }jik078u7uut9890999999999999999999999999999999999999999999999999999999999999995u8
|
|
|
|
// },
|
2023-11-15 09:08:20 +08:00
|
|
|
}
|
2024-03-27 17:02:44 +08:00
|
|
|
],
|
|
|
|
series: series
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-11-15 09:08:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
2024-01-17 15:30:47 +08:00
|
|
|
<style>
|
|
|
|
.productChart{
|
2024-02-01 16:48:58 +08:00
|
|
|
position: absolute;
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
top: -30px;
|
2024-01-17 15:30:47 +08:00
|
|
|
}
|
|
|
|
</style>
|