|
|
@@ -96,42 +96,265 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
- import * as echarts from "echarts"
|
|
|
- export default {
|
|
|
- name: "HardwareData",
|
|
|
- data() {
|
|
|
- return {
|
|
|
- powerChartInstance: null,
|
|
|
- waterChartInstance: null,
|
|
|
- // 模拟月度数据
|
|
|
- monthlyData: [
|
|
|
- { month: "十二月", power: 220000, water: 180000 },
|
|
|
- { month: "一月", power: 210000, water: 170000 },
|
|
|
- { month: "二月", power: 230000, water: 190000 },
|
|
|
- { month: "三月", power: 225000, water: 185000 },
|
|
|
- { month: "四月", power: 215000, water: 175000 },
|
|
|
- { month: "五月", power: 200000, water: 160000 },
|
|
|
- { month: "六月", power: 205000, water: 165000 },
|
|
|
- { month: "七月", power: 210000, water: 170000 },
|
|
|
- { month: "八月", power: 215000, water: 175000 },
|
|
|
- { month: "九月", power: 220000, water: 180000 },
|
|
|
- { month: "十月", power: 225000, water: 185000 },
|
|
|
- { month: "十一月", power: 230000, water: 190000 },
|
|
|
- ],
|
|
|
+import * as echarts from 'echarts'
|
|
|
+export default {
|
|
|
+ name: 'HardwareData',
|
|
|
+ data () {
|
|
|
+ return {
|
|
|
+ powerChartInstance: null,
|
|
|
+ waterChartInstance: null,
|
|
|
+ // 模拟月度数据
|
|
|
+ monthlyData: [
|
|
|
+ { month: '十二月', power: 220000, water: 180000 },
|
|
|
+ { month: '一月', power: 210000, water: 170000 },
|
|
|
+ { month: '二月', power: 230000, water: 190000 },
|
|
|
+ { month: '三月', power: 225000, water: 185000 },
|
|
|
+ { month: '四月', power: 215000, water: 175000 },
|
|
|
+ { month: '五月', power: 200000, water: 160000 },
|
|
|
+ { month: '六月', power: 205000, water: 165000 },
|
|
|
+ { month: '七月', power: 210000, water: 170000 },
|
|
|
+ { month: '八月', power: 215000, water: 175000 },
|
|
|
+ { month: '九月', power: 220000, water: 180000 },
|
|
|
+ { month: '十月', power: 225000, water: 185000 },
|
|
|
+ { month: '十一月', power: 230000, water: 190000 }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mounted () {
|
|
|
+ this.initPowerChart()
|
|
|
+ this.initWaterChart()
|
|
|
+ window.addEventListener('resize', this.handleResize)
|
|
|
+ },
|
|
|
+ beforeDestroy () {
|
|
|
+ window.removeEventListener('resize', this.handleResize)
|
|
|
+ if (this.powerChartInstance) {
|
|
|
+ this.powerChartInstance.dispose()
|
|
|
+ }
|
|
|
+ if (this.waterChartInstance) {
|
|
|
+ this.waterChartInstance.dispose()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ // 初始化用电量柱状图
|
|
|
+ initPowerChart () {
|
|
|
+ this.powerChartInstance = echarts.init(this.$refs.powerChart)
|
|
|
+
|
|
|
+ const option = {
|
|
|
+ tooltip: {
|
|
|
+ trigger: 'axis',
|
|
|
+ backgroundColor: 'rgba(0, 0, 0, 0.8)',
|
|
|
+ borderColor: 'rgba(64, 158, 255, 0.3)',
|
|
|
+ textStyle: {
|
|
|
+ color: '#fff'
|
|
|
+ },
|
|
|
+ formatter: (params) => {
|
|
|
+ let result = ``
|
|
|
+ params.forEach((param) => {
|
|
|
+ result += `${param.name}<br/>${
|
|
|
+ param.seriesName
|
|
|
+ }: ${param.value.toLocaleString()}<br/>`
|
|
|
+ })
|
|
|
+ return result
|
|
|
+ }
|
|
|
+ },
|
|
|
+ grid: {
|
|
|
+ left: '1%',
|
|
|
+ right: '1%',
|
|
|
+ top: '5%',
|
|
|
+ bottom: '2%',
|
|
|
+ containLabel: true
|
|
|
+ },
|
|
|
+ xAxis: {
|
|
|
+ type: 'category',
|
|
|
+ data: this.monthlyData.map((item) => item.month),
|
|
|
+ axisLine: {
|
|
|
+ lineStyle: {
|
|
|
+ color: 'rgba(160, 179, 214, 0.3)',
|
|
|
+ type: 'dashed'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ axisLabel: {
|
|
|
+ color: 'rgba(160, 179, 214, 0.7)',
|
|
|
+ fontSize: 11,
|
|
|
+ interval: 0
|
|
|
+ },
|
|
|
+ axisTick: {
|
|
|
+ show: false
|
|
|
+ },
|
|
|
+ splitLine: {
|
|
|
+ show: true,
|
|
|
+ // 将坐标轴内的线设置为虚线
|
|
|
+ lineStyle: {
|
|
|
+ color: 'rgba(160, 179, 214, 0.3)',
|
|
|
+ type: 'dashed'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ yAxis: {
|
|
|
+ type: 'value',
|
|
|
+ axisLine: {
|
|
|
+ show: false
|
|
|
+ },
|
|
|
+ axisLabel: {
|
|
|
+ color: 'rgba(160, 179, 214, 0.7)',
|
|
|
+ fontSize: 11
|
|
|
+ },
|
|
|
+ axisTick: {
|
|
|
+ show: false
|
|
|
+ },
|
|
|
+ splitLine: {
|
|
|
+ lineStyle: {
|
|
|
+ color: 'rgba(160, 179, 214, 0.1)',
|
|
|
+ type: 'dashed',
|
|
|
+ width: 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ series: [
|
|
|
+ {
|
|
|
+ name: '用电量',
|
|
|
+ type: 'bar',
|
|
|
+ data: this.monthlyData.map((item) => item.power),
|
|
|
+ barWidth: '30%',
|
|
|
+ itemStyle: {
|
|
|
+ color: new echarts.graphic.LinearGradient(1, 1, 0, 0, [
|
|
|
+ { offset: 0, color: '#FCE2B4' },
|
|
|
+ { offset: 1, color: '#F66757' }
|
|
|
+ ]),
|
|
|
+ borderRadius: [20, 20, 0, 0]
|
|
|
+ },
|
|
|
+ label: {
|
|
|
+ show: true,
|
|
|
+ position: 'top',
|
|
|
+ color: '#fff',
|
|
|
+ fontSize: 10,
|
|
|
+ formatter: (params) =>
|
|
|
+ params.value >= 10000
|
|
|
+ ? (params.value / 10000).toFixed(1) + '万'
|
|
|
+ : params.value
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
}
|
|
|
+
|
|
|
+ this.powerChartInstance.setOption(option)
|
|
|
},
|
|
|
- mounted() {
|
|
|
- this.initPowerChart()
|
|
|
- this.initWaterChart()
|
|
|
- window.addEventListener("resize", this.handleResize)
|
|
|
+
|
|
|
+ // 初始化用水量柱状图
|
|
|
+ initWaterChart () {
|
|
|
+ this.waterChartInstance = echarts.init(this.$refs.waterChart)
|
|
|
+
|
|
|
+ const option = {
|
|
|
+ tooltip: {
|
|
|
+ trigger: 'axis',
|
|
|
+ backgroundColor: 'rgba(0, 0, 0, 0.8)',
|
|
|
+ borderColor: 'rgba(64, 158, 255, 0.3)',
|
|
|
+ textStyle: {
|
|
|
+ color: '#fff'
|
|
|
+ },
|
|
|
+ formatter: (params) => {
|
|
|
+ let result = ``
|
|
|
+ params.forEach((param) => {
|
|
|
+ result += `${param.name}<br/>${
|
|
|
+ param.seriesName
|
|
|
+ }: ${param.value.toLocaleString()}<br/>`
|
|
|
+ })
|
|
|
+ return result
|
|
|
+ }
|
|
|
+ },
|
|
|
+ grid: {
|
|
|
+ left: '1%',
|
|
|
+ right: '1%',
|
|
|
+ top: '2%',
|
|
|
+ bottom: '5%',
|
|
|
+ containLabel: true
|
|
|
+ },
|
|
|
+ xAxis: {
|
|
|
+ type: 'category',
|
|
|
+ data: this.monthlyData.map((item) => item.month),
|
|
|
+ axisLine: {
|
|
|
+ lineStyle: {
|
|
|
+ color: 'rgba(160, 179, 214, 0.3)',
|
|
|
+ type: 'dashed'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ axisLabel: {
|
|
|
+ color: 'rgba(160, 179, 214, 0.7)',
|
|
|
+ fontSize: 11,
|
|
|
+ interval: 0,
|
|
|
+ show: false
|
|
|
+ },
|
|
|
+ axisTick: {
|
|
|
+ show: false
|
|
|
+ },
|
|
|
+ splitLine: {
|
|
|
+ show: true,
|
|
|
+ // 将坐标轴内的线设置为虚线
|
|
|
+ lineStyle: {
|
|
|
+ color: 'rgba(160, 179, 214, 0.3)',
|
|
|
+ type: 'dashed'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ yAxis: {
|
|
|
+ type: 'value',
|
|
|
+ // 反转 y 轴的 min 和 max,实现“倒立”
|
|
|
+ min: 400000,
|
|
|
+ max: 0,
|
|
|
+ axisLine: {
|
|
|
+ show: false
|
|
|
+ },
|
|
|
+ axisLabel: {
|
|
|
+ color: 'rgba(160, 179, 214, 0.7)',
|
|
|
+ fontSize: 11
|
|
|
+ },
|
|
|
+ axisTick: {
|
|
|
+ show: false
|
|
|
+ },
|
|
|
+ splitLine: {
|
|
|
+ lineStyle: {
|
|
|
+ color: 'rgba(160, 179, 214, 0.1)',
|
|
|
+ type: 'dashed',
|
|
|
+ width: 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ series: [
|
|
|
+ {
|
|
|
+ name: '用水量',
|
|
|
+ type: 'bar',
|
|
|
+ data: this.monthlyData.map((item) => item.water),
|
|
|
+ barWidth: '30%',
|
|
|
+ itemStyle: {
|
|
|
+ color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
|
|
+ { offset: 0, color: '#3AB3E3' },
|
|
|
+ { offset: 1, color: '#1620D4' }
|
|
|
+ ]),
|
|
|
+ borderRadius: [0, 0, 20, 20]
|
|
|
+ },
|
|
|
+ label: {
|
|
|
+ show: true,
|
|
|
+ position: 'bottom',
|
|
|
+ color: '#fff',
|
|
|
+ fontSize: 10,
|
|
|
+ formatter: (params) =>
|
|
|
+ params.value >= 10000
|
|
|
+ ? (params.value / 10000).toFixed(1) + '万'
|
|
|
+ : params.value
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+
|
|
|
+ this.waterChartInstance.setOption(option)
|
|
|
},
|
|
|
- beforeDestroy() {
|
|
|
- window.removeEventListener("resize", this.handleResize)
|
|
|
+
|
|
|
+ handleResize () {
|
|
|
if (this.powerChartInstance) {
|
|
|
- this.powerChartInstance.dispose()
|
|
|
+ this.powerChartInstance.resize()
|
|
|
}
|
|
|
if (this.waterChartInstance) {
|
|
|
- this.waterChartInstance.dispose()
|
|
|
+ this.waterChartInstance.resize()
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
@@ -361,6 +584,7 @@
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|