123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- <template>
- <div ref="chart" class="chart" :style="{height: '400px', width: '100%'}" />
- </template>
- <script>
- import * as echarts from "echarts";
- import resize from '@/utils/resize'
- export default {
- mixins: [resize],
- props: {
- plain: Object,
- onlyShowCurrentPlain: {
- type: Boolean,
- default: false,
- }
- },
- mounted() {
- this.$nextTick(() => {
- this.chart = echarts.init(this.$refs.chart, 'macarons');
- })
- },
- beforeDestroy() {
- if (!this.chart) {
- return
- }
- this.chart.dispose()
- this.chart = null
- },
- watch: {
- plain: {
- handler(value) {
- this.setOptions(value)
- },
- deep: true,
- immediate: true,
- }
- },
- methods: {
- setOptions(plain) {
- if (!this.chart) {
- return;
- }
- const { sections, wlevelmax, wlevelmin, list, waterlevel } = plain;
- const xAxisData = sections.map(({ x }) => x);
- const seriesData = sections.map(({ x, y }) => ([x, y]));
- const options = {
- xAxis: {
- name: '起点距',
- boundaryGap: false,
- type: 'value',
- min: 'dataMin',
- max: 'dataMax',
- axisLine: {
- lineStyle: {
- color: '#FF8500'
- }
- },
- axisTick: {
- lineStyle: {
- color: '#8D99A4'
- }
- },
- axisLabel: {
- color: '#54606C'
- },
- nameTextStyle: {
- color: '#54606C'
- }
- },
- yAxis: [
- {
- name: '高程(m)',
- triggerEvent: true,
- axisLine: {
- show: true,
- lineStyle: {
- color: '#FF8500'
- }
- },
- axisTick: {
- show: true,
- lineStyle: {
- color: '#8D99A4'
- }
- },
- axisLabel: {
- color: '#54606C'
- },
- nameTextStyle: {
- 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: '高程',
- lineStyle: {
- width: 1,
- color: '#FF8500',
- },
- areaStyle: {
- opacity: 1,
- color: '#ffc27f',
- },
- smooth: false,
- symbol: 'none',
- type: 'line',
- data: seriesData,
- animations: false,
- markLine: {
- symbol: 'none',
- silent: true,
- lineStyle: { normal: { type: 'dashed' } },
- label: { position: 'start' },
- data: [
- {
- yAxis: wlevelmax,
- lineStyle: { width: 1, color: 'red' },
- name: '最高水位',
- label: {
- formatter: '{b}'
- }
- },
- {
- yAxis: wlevelmin,
- lineStyle: { width: 1, color: 'red' },
- name: '最低水位',
- label: {
- formatter: '{b}'
- }
- },
- ]
- },
- }]
- };
- if (waterlevel) {
- options.series.push({
- data: [[Math.min(...xAxisData), waterlevel],[Math.max(...xAxisData), waterlevel]],
- type: 'line',
- symbol: 'none',
- z: 0,
- lineStyle: {
- width: 0,
- },
- areaStyle: {
- opacity: 1,
- color: '#a5cdf7',
- }
- })
- }
- let hasSetCurrent = false;
- list.forEach((plain, index) => {
- const themes = [
- '#2ec7c9',
- '#b6a2de',
- '#5ab1ef',
- '#d87a80',
- '#8d98b3',
- '#97b552',
- '#95706d',
- '#dc69aa',
- '#07a2a4',
- '#9a7fd1',
- ]
- const { wlevel, positions, planid } = plain;
- if (this.onlyShowCurrentPlain && (hasSetCurrent || wlevel > waterlevel)) {
- return;
- } else {
- hasSetCurrent = true;
- }
- const positions1 = JSON.parse(positions) || [];
- const pointsData = positions1.reduce((init, p) => {
- const xIndex = xAxisData.findIndex(x => x === p.x);
- if (xIndex !== -1) {
- init.push({ coord: [p.x, wlevel] })
- }
- return init;
- }, []);
- options.series.push({
- name: `策略编号(${planid})`,
- symbol: 'none',
- itemStyle: {
- normal: {
- color: themes[index],
- lineStyle: {
- width: 0
- }
- }
- },
- data: xAxisData.map((x) => [x, wlevel]),
- type: 'line',
- markLine: {
- symbol: 'none',
- silent: true,
- lineStyle: {
- color: themes[index],
- },
- label: { position: 'start' },
- data: [{
- yAxis: wlevel,
- name: `策略编号(${planid})`,
- label: {
- formatter: '{b}'
- }
- }],
- },
- markPoint: {
- label: {
- formatter: ({ data }) => data.coord[0],
- },
- itemStyle: {
- color: themes[index],
- },
- data: pointsData,
- },
- });
- })
- this.chart.clear();
- this.chart.setOption(options);
- }
- }
- }
- </script>
- <style scoped>
- </style>
|