<template> <div id="person-bar1" class="container"/> </template> <script> import * as echarts from 'echarts'; import { getTransitrRatio } from '@/api/ywts/shms/sq'; export default { name: 'PersonBar', data() { return { isShow: true, myChart: null, height: '0', width: '0', chartSettings: { labelMap: { date: '时间' }, metrics: [], dimension: ['date'] }, extend: { color: ['#0071ff88', '#00afff88', '#00fdc088'], legend: { textStyle: { color: '#cce9ff', fontWeight: 'bold' }, lineStyle: { width: 10 }, data: ['进', '出'] }, // aria: { // enabled: true, // decal: { // show: true // } // }, tooltip: { trigger: 'axis', axisPointer: { type: 'cross', label: { backgroundColor: '#cce9ff' } } }, grid: { left: '1%', right: '2%', bottom: '1%', top: '15%', containLabel: true }, xAxis: { type: 'category', axisLine: { lineStyle: { color: '#cce9ff' } }, axisLabel: { color: '#cce9ff' } }, yAxis: { position: 'left', type: 'value', axisLine: { lineStyle: { color: '#cce9ff' } }, axisLabel: { color: '#cce9ff' } }, series: [ { name: '进', type: 'bar', barMaxWidth: 30, label: { show: true, position: 'insideTop' }, // decal: { // symbol: 'circle' // }, itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 1, color: 'rgba(255,190,68,0.4)' }, // { offset: 0.3, color: 'rgba(0,253,232,0.8)' }, { offset: 0, color: '#82b4dc' } ]) } }, { name: '出', type: 'bar', barMaxWidth: 30, label: { show: true, position: 'insideTop' }, // decal: { // symbol: 'circle' // }, itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 1, color: 'rgba(255,190,68,0.4)' }, // { offset: 0.3, color: 'rgba(0,253,232,0.8)' }, { offset: 0, color: '#4ab228' } ]) } }, ] }, chartData: { columns: [], rows: [] } } }, mounted() { this.myChart = echarts.init(document.getElementById('person-bar1')) this.height = document.getElementById('person-bar1').clientHeight - 10 + 'px' this.width = document.getElementById('person-bar1').clientWidth - 10 + 'px' const that = this window.addEventListener('resize', function() { if(!document.getElementById('person-bar1')) { return } that.reload() }) }, methods: { async reload() { this.isShow = false await this.$nextTick() this.height = document.getElementById('person-bar1').clientHeight - 10 + 'px' this.width = document.getElementById('person-bar1').clientWidth - 10 + 'px' this.isShow = true }, // 获取数据 fetchData(id) { getTransitrRatio({id}).then(response => { console.log(response.data, '通行量分析') if (response.code === 200) { // this.chartData.rows = response.data this.extend.series[0].data = response.data.value.map(item => item.in) this.extend.series[1].data = response.data.value.map(item => item.out) this.extend.xAxis.data = response.data.value.map(item => item.date) this.myChart.setOption(this.extend, true) } }) // this.extend.series[0].data = [5154,4545,2455,7212] // this.extend.series[1].data = [554,545,455,722] // this.extend.xAxis.data = ['20岁以下', '20-30岁', '30-40岁', '40岁以上' ] // this.myChart.setOption(this.extend, true) } } } </script> <style lang="scss" scoped> .container{ position:relative; width: 100%; height:100%; } </style>