<template> <div id="staff-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 { multiScoreCommute } from '@/api/pop' import * as echarts from 'echarts' export default { name: 'StaffLine1', data() { return { isShow: true, 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: ['安防评分'] }, tooltip: { trigger: 'axis', axisPointer: { type: 'cross', label: { backgroundColor: '#cce9ff' } } }, grid: { left: '1%', right: '2%', bottom: '0%', top: '20%', containLabel: true }, xAxis: { type: 'category', boundaryGap: false, axisLabel: { color: '#cce9ff' } }, yAxis: { position: 'left', type: 'value', axisLabel: { color: '#cce9ff' } }, series: { type: 'line', // top / left / right / bottom / inside / insideLeft / insideRight / insideTop / insideBottom / insideTopLeft / insideBottomLeft / insideTopRight / insideBottomRight label: { show: true, position: 'insideBottom' }, symbol: 'circle', symbolSize: 6, areaStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0.2, color: '#0156b755' }, { offset: 0.5, color: 'rgba(10,25,124,0.2)' } ]) }, emphasis: { focus: 'series' } } }, chartData: { columns: [], rows: [] } } }, mounted() { this.height = document.getElementById('staff-line').clientHeight - 10 + 'px' this.width = document.getElementById('staff-line').clientWidth - 10 + 'px' const that = this window.addEventListener('resize', function() { that.reload() }) this.fetchData() }, methods: { async reload() { this.isShow = false await this.$nextTick() this.height = document.getElementById('staff-line').clientHeight - 10 + 'px' this.width = document.getElementById('staff-line').clientWidth - 10 + 'px' this.isShow = true }, // 获取数据 fetchData() { this.chartData.columns = ['date', 'score'] this.chartSettings.metrics = ['score'] this.chartSettings.labelMap = { 'date': '时间', 'score': '安防评分' } multiScoreCommute().then(response => { console.log(response) if (response.code === 200) { this.chartData.rows = response.data } }) } } } </script> <style lang="scss" scoped> .container{ position:relative; width: 100%; height:100%; } </style>