<template> <div id="power-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'; export default { name: 'PowerLine', data() { return { isShow: true, title: { text: '机动力量', textStyle: { color: '#cce9ff', fontSize: 15 }, padding: [5, 0, 0, 120] }, height: '0', width: '0', chartSettings: { labelMap: { time: '时间' }, metrics: [], dimension: ['time'] }, extend: { grid: { bottom: '2%', top: '10%', containLabel: true }, yAxis: { axisLabel: { color: '#cce9ff' } }, xAxis: { axisLabel: { color: '#cce9ff' } }, legend: { show: false, // type: 'scroll', top: '0px', textStyle: { color: '#cce9ff', fontWeight: 'bold' } }, series: { color: '#82b4dc', type: 'line', symbol: 'circle', symbolSize: 8, stack: 'Total', areaStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0.2, color: 'rgba(255,190,68,0.4)' }, { offset: 0.5, color: '#0156b755' } ]) }, 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('power-line').clientHeight - 10 + 'px' this.width = document.getElementById('power-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('power-line').clientHeight - 10 + 'px' this.width = document.getElementById('power-line').clientWidth - 10 + 'px' this.isShow = true }, // 获取数据 fetchData() { // statisticsMonth().then(response => { // if(response.data.length>0){ // const arr = response.data.map((item)=> { // const result = {time: item.time} // for (let i = 0; i < item.data.length; i++) { // result[item.data[i].name] = item.data[i].count // } // return result // }) // const area = response.data[0].data.map(item=>item.name) // this.chartData.columns = ['time', ...area] // this.chartSettings.metrics = area // this.chartSettings.labelMap = {'time':'月份'} // this.chartData.rows = arr // } // }) this.chartData.columns = ['time', '机动力量'] this.chartSettings.metrics = ['机动力量'] this.chartSettings.labelMap = { 'time': '月份' } // 模拟数据 this.chartData.rows = [ { time: '0', '机动力量': '0.9' }, { time: '1', '机动力量': '0.9' }, { time: '2', '机动力量': '0.8' }, { time: '3', '机动力量': '0.75' }, { time: '4', '机动力量': '0.88' }, { time: '5', '机动力量': '0.78' }, { time: '6', '机动力量': '0.86' }, { time: '7', '机动力量': '0.82' }, { time: '8', '机动力量': '0.94' }, { time: '9', '机动力量': '0.96' }, { time: '10', '机动力量': '0.94' }, { time: '11', '机动力量': '0.92' }, { time: '12', '机动力量': '0.95' }, { time: '13', '机动力量': '0.87' }, { time: '14', '机动力量': '0.92' }, { time: '15', '机动力量': '0.91' }, { time: '16', '机动力量': '0.9' }, { time: '17', '机动力量': '0.9' }, { time: '18', '机动力量': '0.92' }, { time: '19', '机动力量': '0.85' }, { time: '20', '机动力量': '0.88' }, { time: '21', '机动力量': '0.86' }, { time: '22', '机动力量': '0.87' }, { time: '23', '机动力量': '0.89' } ] } } } </script> <style lang="scss" scoped> .container{ position:relative; width: 100%; height:100%; } </style>