123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <template>
- <div ref="chart" class="chart" :style="{height: '400px', width: '100%'}" />
- </template>
- <script>
- import { listWaterLevel } from '@/api/analysis/achievement'
- import * as echarts from "echarts";
- require('echarts/theme/macarons') // echarts theme
- import resize from '@/utils/resize'
- export default {
- mixins: [resize],
- props: {
- queryParams: Object,
- },
- data() {
- return {
- pagination: {
- page: 1,
- size: 10000,
- }
- }
- },
- mounted() {
- this.$nextTick(() => {
- this.chart = echarts.init(this.$refs.chart, 'macarons');
- this.setOptions();
- })
- },
- beforeDestroy() {
- if (!this.chart) {
- return
- }
- this.chart.dispose()
- this.chart = null
- },
- methods: {
- setOptions() {
- const { queryParams } = this;
- if (!queryParams.siteId) return;
- const params = {
- ...this.queryParams,
- ...this.pagination,
- };
- listWaterLevel(params).then((res) => {
- const chartData = res.data.records || [];
- chartData.reverse()
- const xAxisData = chartData.map(({ time }) => time);
- const seriesData = chartData.map(({ avgWaterlevel }) => avgWaterlevel);
- this.chart.setOption({
- xAxis: {
- name: '时间',
- boundaryGap: false,
- data: xAxisData,
- type: 'category',
- axisLine: {
- lineStyle: {
- color: '#54606C'
- }
- },
- },
- yAxis: [
- {
- name: '水位(m)',
- axisLine: {
- lineStyle: {
- color: '#54606C'
- }
- },
- min: 'dataMin',
- max: 'dataMax',
- },
- {
- axisLine: {
- show: true,
- lineStyle: {
- color: '#FF8500'
- }
- },
- axisTick: {
- show: false,
- },
- axisLabel: {
- show: false,
- },
- },
- ],
- grid: {
- left: 50,
- right: 50,
- bottom: 40,
- top: 40,
- containLabel: true
- },
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- type: 'cross'
- },
- padding: [5, 10]
- },
- series: [{
- name: '水位',
- itemStyle: {
- normal: {
- color: '#FF8500',
- lineStyle: {
- color: '#FF8500',
- width: 2
- }
- }
- },
- smooth: false,
- type: 'line',
- data: seriesData,
- animations: false,
- }]
- })
- })
- }
- },
- watch: {
- queryParams: {
- handler() {
- this.setOptions();
- },
- deep: true,
- },
- }
- }
- </script>
- <style scoped>
- </style>
|