<template> <div id="ts-linebar" class="container" /> </template> <script> // import { multiScoreKeyArea} from '@/api/pop'; import * as echarts from 'echarts'; import { getRate } from "../../../../../api/ywts/shms/jy"; export default { name: 'TsLineBar', 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: ['教师人数', '学生人数', '师生比'] }, tooltip: { trigger: 'axis', axisPointer: { type: 'cross', label: { backgroundColor: '#cce9ff' } } }, grid: { left: '5%', right: '5%', bottom: '0%', top: '15%', containLabel: true }, xAxis: { type: 'category', axisLine: { lineStyle: { color: '#cce9ff' } }, axisLabel: { color: '#cce9ff' } }, yAxis: [ { name: '人数', position: 'left', type: 'value', axisLine: { lineStyle: { color: '#cce9ff' } }, axisLabel: { color: '#cce9ff' } }, { name: '师生比', position: 'right', type: 'value', axisLine: { lineStyle: { color: '#cce9ff' } }, axisLabel: { color: '#cce9ff' } } ], series: [ { name: '教师人数', type: 'bar', barMaxWidth: 30, label: { show: true, position: 'insideTop' }, itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 1, color: 'rgba(10,25,124,0.0)' }, { offset: 0.3, color: 'rgba(0,253,232,0.8)' }, { offset: 0, color: 'rgba(0,178,172,0.8)' } ]) } }, { name: '学生人数', type: 'bar', barMaxWidth: 30, label: { show: true, position: 'insideTop' }, itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 1, color: 'rgba(10,25,124,0.0)' }, { offset: 0.3, color: 'rgba(0,253,232,0.8)' }, { offset: 0, color: 'rgba(0,178,172,0.8)' } ]) } }, { name: '师生比', yAxisIndex: 1, type: 'line', symbol: 'circle', symbolSize: 6, color: 'rgba(255,190,68,1)', areaStyle: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ { offset: 0.5, color: 'rgba(255,190,68,0.7)', }, { offset: 1, color: 'rgba(10,25,124,0.2)' } ]) }, emphasis: { focus: 'series' }, label: { show: true, position: 'insideBottom' } } ] }, chartData: { columns: [], rows: [] } } }, mounted() { this.myChart = echarts.init(document.getElementById('ts-linebar')) this.height = document.getElementById('ts-linebar').clientHeight - 10 + 'px' this.width = document.getElementById('ts-linebar').clientWidth - 10 + 'px' const that = this window.addEventListener('resize', function () { if (!document.getElementById('ts-linebar')) { return } that.reload() }) }, methods: { async reload() { this.isShow = false await this.$nextTick() this.height = document.getElementById('ts-linebar').clientHeight - 10 + 'px' this.width = document.getElementById('ts-linebar').clientWidth - 10 + 'px' this.isShow = true }, // 获取数据 fetchData(id) { getRate(id).then(res => { if (res.code === 200) { const data = res.data.value console.log(data) if (data.length !== 0) { this.extend.series[0].data = data.map(item => item.teacher) this.extend.series[1].data = data.map(item => item.student) this.extend.series[2].data = data.map(item => item.rate.replace('%', '')) this.extend.xAxis.data = data.map(item => item.month) this.myChart.setOption(this.extend, true) } } }) // this.extend.series[0].data = [5154,4545,2455,7212,4545,2455,7212] // this.extend.series[1].data = [554,455,455,721,445,455,712] // this.extend.series[2].data = [1,0.5,1,1.5,1,1.8,0.9] // this.extend.xAxis.data = ['1','2','3','4','5','6','7'] // this.myChart.setOption(this.extend, true) } } } </script> <style lang="scss" scoped> .container { position: relative; width: 100%; height: 100%; } </style>