yudao-dev/src/views/OperationalOverview/components/pileBarChart.vue

216 lines
4.6 KiB
Vue
Raw Normal View History

2023-12-29 09:00:00 +08:00
<!--
* @Author: zhp
* @Date: 2023-12-27 13:54:52
2023-12-29 16:29:15 +08:00
* @LastEditTime: 2023-12-29 16:28:26
2023-12-29 09:00:00 +08:00
* @LastEditors: zhp
* @Description:
-->
<template>
<div>
<div :id="id" :class="className" :style="{ height: height + 'px', width: width }" />
</div>
</template>
<script>
import * as echarts from 'echarts';
import 'echarts/theme/macarons' // echarts theme
import resize from './mixins/resize'
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,
nameList: [],
series: [{
type: 'bar',
data: [],
barWidth: 6
}]
}
},
mounted() {
console.log('mounted')
// console.log('borderRadius: ', this.borderRadius)
// console.log('33333', this.dataList)
// let arr = []
// this.dataList.forEach(ele => {
// console.log(ele);
// this.series = []
this.initChart()
// this.$nextTick(() => {
// // this.initChart()
// })
},
beforeDestroy() {
if (!this.chart) {
return
}
this.chart.dispose()
this.chart = null
},
methods: {
initChart(nameList, topNameList, nameWasteList, passRateList, wasteList) {
// console.log(1)
this.chart = echarts.init(document.getElementById(this.id))
2023-12-29 16:29:15 +08:00
let series = [
{
// 辅助系列
name: '良品',
type: 'bar',
stack: 'total',
// silent: true,
// itemStyle: {
color: '#0fdedb',
// },
barWidth: 10,
data: passRateList
2023-12-29 09:00:00 +08:00
},
2023-12-29 16:29:15 +08:00
{
type: 'bar',
stack: 'total',
name: '废品',
data: wasteList,
barWidth: 10,
// barWidth: 15,
// label: {
// position: [10, 10],
// normal: {
// position: [800, -24],
// show: true,
// textStyle: {
// color: '#2359ec',
// fontSize: 16,
// },
// },
// },
2023-12-29 09:00:00 +08:00
}
2023-12-29 16:29:15 +08:00
]
2023-12-29 09:00:00 +08:00
// for (i = 0; i < 5; i++) {
// series.push({
// })
// }
this.chart.setOption({
2023-12-29 16:29:15 +08:00
legend: {
textStyle: {
color: '#ffffff'
2023-12-29 09:00:00 +08:00
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
width: 'auto',
height: 'auto',
containLabel: true
},
yAxis: [
{
2023-12-29 16:29:15 +08:00
type: 'category',
2023-12-29 09:00:00 +08:00
inverse: true,
2023-12-29 16:29:15 +08:00
splitLine: {
show: false
},
axisTick: {
show: false
},
axisLine: {
show: false
},
2023-12-29 09:00:00 +08:00
axisLabel: {
show: true,
inside: true,
2023-12-29 16:29:15 +08:00
interval: 0, //横轴信息全部显
splitNumber: 50,
// boundaryGap: [20, 20],
2023-12-29 09:00:00 +08:00
textStyle: {
color: '#ffffff',
2023-12-29 16:29:15 +08:00
verticalAlign: 'bottom',
2023-12-29 09:00:00 +08:00
fontSize: 12,
align: 'left',
2023-12-29 16:29:15 +08:00
padding: [0, 0, 15, -5]
2023-12-29 09:00:00 +08:00
}
},
2023-12-29 16:29:15 +08:00
data: topNameList
},
{
type: 'category',
inverse: true,
2023-12-29 09:00:00 +08:00
splitLine: {
show: false
},
axisTick: {
show: false
},
axisLine: {
show: false
2023-12-29 16:29:15 +08:00
},
2023-12-29 09:00:00 +08:00
axisLabel: {
2023-12-29 16:29:15 +08:00
show: true,
2023-12-29 09:00:00 +08:00
inside: true,
2023-12-29 16:29:15 +08:00
interval: 0, //横轴信息全部显
splitNumber: 50,
// boundaryGap: [20, 20],
2023-12-29 09:00:00 +08:00
textStyle: {
color: '#ffffff',
2023-12-29 16:29:15 +08:00
verticalAlign: 'bottom',
2023-12-29 09:00:00 +08:00
fontSize: 12,
align: 'right',
2023-12-29 16:29:15 +08:00
padding: [0, 0, 15, -5]
2023-12-29 09:00:00 +08:00
}
},
2023-12-29 16:29:15 +08:00
data: nameWasteList
2023-12-29 09:00:00 +08:00
}
],
2023-12-29 16:29:15 +08:00
xAxis: {
// max: 120,
show: false,
},
series:series
2023-12-29 09:00:00 +08:00
})
}
}
}
</script>