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

264 lines
6.0 KiB
Vue
Raw Normal View History

2023-12-29 09:00:00 +08:00
<!--
* @Author: zhp
* @Date: 2023-12-27 13:54:52
2024-03-25 18:42:00 +08:00
* @LastEditTime: 2024-03-25 18:37:26
2023-12-29 09:00:00 +08:00
* @LastEditors: zhp
* @Description:
-->
<template>
<div>
2024-01-17 15:30:47 +08:00
<div :id="id" class="productChart" :style="{ height: height + 'px', width: width }" />
2023-12-29 09:00:00 +08:00
</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) {
2024-02-21 15:27:09 +08:00
let rawData = []
2024-03-25 16:57:41 +08:00
let colors = ['#0fdedb', '#2359ec']
if (passRateList && wasteList) {
rawData.push(passRateList, wasteList)
// console.log(1)
const totalData = [];
for (let i = 0; i < rawData[0].length; ++i) {
let sum = 0;
for (let j = 0; j < rawData.length; ++j) {
sum += rawData[j][i];
}
totalData.push(sum);
2024-02-21 15:27:09 +08:00
}
2024-03-25 16:57:41 +08:00
console.log('total', totalData);
2024-02-21 15:27:09 +08:00
}
2023-12-29 09:00:00 +08:00
this.chart = echarts.init(document.getElementById(this.id))
2024-02-21 15:27:09 +08:00
const series = [
'良品',
'废品',
// 'Affiliate Ad',
// 'Video Ad',
// 'Search Engine'
].map((name, sid) => {
// console.log(sid)
return {
name,
2023-12-29 16:29:15 +08:00
type: 'bar',
stack: 'total',
barWidth: 10,
2024-02-21 15:27:09 +08:00
label: {
show: true,
formatter: (params) => Math.round(params.value * 1000) / 10 + '%'
},
color:colors[sid],
2024-03-25 16:57:41 +08:00
data: rawData.length != 0 ? rawData[sid].map((d, did) =>
2024-02-21 15:27:09 +08:00
totalData[did] <= 0 ? 0 : d / totalData[did]
2024-03-25 16:57:41 +08:00
) : []
2024-02-21 15:27:09 +08:00
};
});
// let series = [
// {
// // 辅助系列
// name: '良品',
// type: 'bar',
// stack: 'total',
// // silent: true,
// // itemStyle: {
// color: '#0fdedb',
// // },
// // barCategoryGap: '10%',
// barWidth: 10,
// data: passRateList
// },
// {
// type: 'bar',
// stack: 'total',
// name: '废品',
// // barCategoryGap: '10%',
// 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
// for (i = 0; i < 5; i++) {
// series.push({
// })
// }
this.chart.setOption({
2023-12-29 16:29:15 +08:00
legend: {
2024-03-13 14:54:35 +08:00
itemWidth: 12,
itemHeight: 12,
2024-03-25 18:42:00 +08:00
top:'10',
2024-02-21 15:27:09 +08:00
icon: 'rect',
2023-12-29 16:29:15 +08:00
textStyle: {
color: '#ffffff'
2023-12-29 09:00:00 +08:00
}
},
grid: {
2024-01-17 15:30:47 +08:00
top:'80',
2023-12-29 09:00:00 +08:00
left: '3%',
right: '4%',
2024-01-17 15:30:47 +08:00
// bottom: '3%',
2023-12-29 09:00:00 +08:00
width: 'auto',
2024-01-25 16:10:31 +08:00
height: '300',
2023-12-29 09:00:00 +08:00
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>
2024-01-17 15:30:47 +08:00
<style scoped lang="scss">
</style>