2023-11-15 09:08:20 +08:00
|
|
|
<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
|
|
|
|
},
|
2023-12-29 09:00:00 +08:00
|
|
|
// nameList: {
|
|
|
|
// type: Array,
|
|
|
|
// default: () => []
|
|
|
|
// },
|
|
|
|
// dataList: {
|
|
|
|
// type: Array,
|
|
|
|
// default: () => []
|
|
|
|
// }
|
2023-11-15 09:08:20 +08:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
chart: null,
|
2023-12-29 09:00:00 +08:00
|
|
|
nameList: [],
|
|
|
|
series: [{
|
|
|
|
type: 'bar',
|
|
|
|
data: [],
|
|
|
|
barWidth: 6
|
|
|
|
|
|
|
|
}]
|
2023-11-15 09:08:20 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
console.log('mounted')
|
|
|
|
console.log('borderRadius: ', this.borderRadius)
|
2023-12-29 09:00:00 +08:00
|
|
|
// console.log('33333', this.dataList)
|
|
|
|
// let arr = []
|
|
|
|
// this.dataList.forEach(ele => {
|
|
|
|
// console.log(ele);
|
|
|
|
// this.series = []
|
|
|
|
this.initChart()
|
|
|
|
// this.$nextTick(() => {
|
|
|
|
// // this.initChart()
|
|
|
|
// })
|
2023-11-15 09:08:20 +08:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
if (!this.chart) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.chart.dispose()
|
|
|
|
this.chart = null
|
|
|
|
},
|
|
|
|
methods: {
|
2024-01-24 17:16:05 +08:00
|
|
|
initChart(nameList, dataList) {
|
|
|
|
console.log('1111', dataList);
|
2023-12-29 09:00:00 +08:00
|
|
|
// console.log(1)
|
2023-11-15 09:08:20 +08:00
|
|
|
this.chart = echarts.init(document.getElementById(this.id))
|
2024-01-24 17:16:05 +08:00
|
|
|
// if (dataList.length !== 0) {
|
2023-12-29 09:00:00 +08:00
|
|
|
// this.$set(this.series, "data", dataList);
|
|
|
|
this.series = [{
|
|
|
|
type: 'bar',
|
|
|
|
data: dataList,
|
2024-01-24 17:16:05 +08:00
|
|
|
itemStyle: {
|
|
|
|
normal: {
|
2024-01-24 17:17:50 +08:00
|
|
|
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
|
|
{ offset: 0, color: '#9DD5FF' },
|
|
|
|
{ offset: 0.3, color: '#1295FF' }
|
|
|
|
]),
|
2024-01-24 17:16:05 +08:00
|
|
|
label: {
|
|
|
|
show: true, //开启显示
|
|
|
|
position: 'top', //在上方显示
|
|
|
|
textStyle: { //数值样式
|
|
|
|
color: '#ced1d5',
|
|
|
|
fontSize: 12
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
// barBorderRadius: this.borderRadius
|
|
|
|
},
|
|
|
|
barWidth: 12,
|
2023-12-29 09:00:00 +08:00
|
|
|
}]
|
2024-01-24 17:16:05 +08:00
|
|
|
// }
|
|
|
|
// if (nameList.length !== 0) {
|
2023-12-29 09:00:00 +08:00
|
|
|
this.nameList = nameList
|
2024-01-24 17:16:05 +08:00
|
|
|
// }
|
2023-11-15 09:08:20 +08:00
|
|
|
this.chart.setOption({
|
|
|
|
tooltip: {
|
|
|
|
trigger: 'axis',
|
|
|
|
axisPointer: {
|
|
|
|
// 坐标轴指示器,坐标轴触发有效
|
|
|
|
type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
grid: {
|
|
|
|
top: 30,
|
|
|
|
left: '2%',
|
|
|
|
right: '2%',
|
|
|
|
bottom: '3%',
|
|
|
|
containLabel: true
|
|
|
|
},
|
2024-01-24 17:16:05 +08:00
|
|
|
// legend: {
|
|
|
|
// itemWidth: 10,
|
|
|
|
// itemHeight: 10,
|
|
|
|
// // right: '20px',
|
|
|
|
// data: nameList,
|
|
|
|
// textStyle: {
|
|
|
|
// fontSize: 12 * this.beilv,
|
|
|
|
// color: '#ced1d5'
|
|
|
|
// }
|
|
|
|
// },
|
2023-11-15 09:08:20 +08:00
|
|
|
xAxis: {
|
|
|
|
type: 'category',
|
|
|
|
axisLine: {
|
|
|
|
lineStyle: {
|
|
|
|
type: 'solid',
|
|
|
|
color: '#213259', // 左边线的颜色
|
|
|
|
width: '1' // 坐标线的宽度
|
|
|
|
}
|
|
|
|
},
|
|
|
|
axisLabel: {
|
|
|
|
textStyle: {
|
|
|
|
color: 'rgba(255,255,255,0.5)' // 坐标值得具体的颜色
|
|
|
|
}
|
|
|
|
},
|
|
|
|
splitLine: {
|
|
|
|
lineStyle: {
|
|
|
|
color: '#213259'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data: this.nameList
|
|
|
|
},
|
|
|
|
yAxis: {
|
|
|
|
axisLine: {
|
|
|
|
lineStyle: {
|
|
|
|
type: 'solid',
|
|
|
|
color: '#213259', // 左边线的颜色
|
|
|
|
width: '1' // 坐标线的宽度
|
|
|
|
}
|
|
|
|
},
|
|
|
|
axisLabel: {
|
2024-01-09 16:25:12 +08:00
|
|
|
show: true, // 是否显示 y 轴
|
2023-11-15 09:08:20 +08:00
|
|
|
textStyle: {
|
|
|
|
color: 'rgba(255,255,255,0.5)' // 坐标值得具体的颜色
|
|
|
|
}
|
|
|
|
},
|
|
|
|
splitLine: {
|
|
|
|
lineStyle: {
|
|
|
|
color: '#213259'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
type: 'value'
|
|
|
|
},
|
2023-12-29 09:00:00 +08:00
|
|
|
// legend: {
|
|
|
|
// itemHeight: 10,
|
|
|
|
// itemWidth: 10,
|
|
|
|
// x: 'center', // 可设定图例在左、右、居中
|
|
|
|
// y: 'top', // 可设定图例在上、下、居中
|
|
|
|
// show: this.showLegend,
|
|
|
|
// data: this.dataList,
|
|
|
|
// right: '1%',
|
|
|
|
// textStyle: {
|
|
|
|
// fontSize: 12 * this.beilv,
|
|
|
|
// color: '#ced1d5'
|
|
|
|
// }
|
|
|
|
// },
|
2023-11-15 09:08:20 +08:00
|
|
|
series: this.series
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
2024-01-17 15:30:47 +08:00
|
|
|
|