<template> <div id="teacher-line" class="container"> <ve-line v-if="isShow" :width='width' :height='height' :judge-width="true" :data="chartData" :extend="extend" :settings="chartSettings" /> </div> </template> <script> import * as echarts from 'echarts'; // import { getTeacherSta } from "../../../../../api/ywts/shms/jy"; // import { multiScoreOther } from '@/api/pop' import { getPassengerFlow } from '@/api/ywts/zyhj/yl' export default { name: 'PersonLine', data() { return { isShow: true, title: { text: '客流量', textStyle: { color: '#cce9ff', fontSize: 15 }, padding: [5, 0, 0, 120] }, height: '0', width: '0', chartSettings: { labelMap: { name: '日期' }, metrics: [], dimension: ['date'] }, extend: { grid: { bottom: '0%', top: '20%', containLabel: true }, yAxis: { axisLabel: { color: '#cce9ff' } }, xAxis: { axisLabel: { color: '#cce9ff' } }, legend: { // show: false, data: ['客流量'], // type: 'scroll', top: '0px', textStyle: { color: '#cce9ff', fontWeight: 'bold' } }, series: { color: '#82b4dc', type: 'line', symbol: 'circle', symbolSize: 8, stack: 'Total', // top / left / right / bottom / inside / insideLeft / insideRight / insideTop / insideBottom / insideTopLeft / insideBottomLeft / insideTopRight / insideBottomRight label: { show: true, position: 'insideBottom' }, areaStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0, color: '#0156b755' }, { offset: 1, color: 'rgba(255,190,68,0.4)' } ]) }, emphasis: { focus: 'series' } }, tooltip: { trigger: 'axis', position: function (pt) { return [pt[0], '10%'] }, formatter: function (params, ticket, callback) { return params[0].data[0] + '<br>人数:' + params[0].data[1] } } }, chartData: { columns: [], rows: [] } } }, mounted() { this.height = document.getElementById('teacher-line').clientHeight - 10 + 'px' this.width = document.getElementById('teacher-line').clientWidth - 10 + 'px' const that = this window.addEventListener('resize', function () { if(!document.getElementById('teacher-line')) { return } that.reload() }) }, methods: { async reload() { if (!document.getElementById('teacher-line')) { return } this.isShow = false await this.$nextTick() this.height = document.getElementById('teacher-line').clientHeight - 10 + 'px' this.width = document.getElementById('teacher-line').clientWidth - 10 + 'px' this.isShow = true }, // 获取数据 fetchData(id) { console.log(1111111111111111111111111111) this.chartData.columns = ['date', 'num'] this.chartSettings.metrics = ['num'] this.chartSettings.labelMap = { 'date': '日期', 'num': '客流量' } getPassengerFlow({id}).then(res => { console.log('人员趋势',res.data.value ) if (res.code === 200) { const data = res.data.value this.chartData.rows = data.map(item => { return { date: item.date, num: item.num } }) this.myChart.setOption(this.extend, true) } }) } } } </script> <style lang="scss" scoped> .container { position: relative; width: 100%; height: 100%; } </style>