<template> <div id="other-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 { multiScoreOther } from '@/api/pop' export default { name: 'OtherLine', 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('other-line').clientHeight - 10 + 'px' this.width = document.getElementById('other-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('other-line').clientHeight - 10 + 'px' this.width = document.getElementById('other-line').clientWidth - 10 + 'px' this.isShow = true }, // 获取数据 fetchData() { multiScoreOther().then(response => { if (response.code === 200) { this.chartData.rows = response.data } }) this.chartData.columns = ['date', 'score'] this.chartSettings.metrics = ['score'] this.chartSettings.labelMap = { 'date': '日期', 'score': '其他相关安防评分' } } } } </script> <style lang="scss" scoped> .container{ position:relative; width: 100%; height:100%; } </style>