| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- <template>
- <div class="main">
- <div class="main_in">
- <weatherTitle2 :title="title.titleText" :title2="title.pageTitle"></weatherTitle2>
- <div>
- <div ref="prediction" style="width: 100%; height: 360px"></div>
- </div>
- </div>
- </div>
- </template>
- <script lang="ts" setup>
- import { toRef, ref, getCurrentInstance, onMounted } from 'vue';
- import eventBus from '/@/utils/eventBus';
- import weatherTitle2 from '../../../components/Title/weatherTitle2.vue';
- const jump = () => {
- eventBus.emit('mapjump', props.title);
- };
- let activeKey = ref('1');
- //组件传参
- const props = defineProps({
- title: { type: Object },
- nodeId: { type: String },
- predictionData: {
- type: Object,
- default: () => {
- return {};
- },
- },
- });
- let datas = toRef(props, 'predictionData');
- // // 计算最大值
- function getMaxValue(arr) {
- const max = Math.max(...arr);
- // 这样处理是为了不让最大值刚好到坐标轴最顶部
- return Math.ceil(max / 9.5) * 10;
- }
- // 计算最小值
- function getMinValue(arr) {
- const min = Math.min(...arr);
- // 这样处理是为了不让最大值刚好到坐标轴最底部
- return Math.floor(min / 12) * 10;
- }
- // 引入图表插件
- const { proxy } = getCurrentInstance();
- const echarts = proxy.$echarts;
- let prediction = ref(null);
- function echarts1() {
- let maxList = [...props.predictionData.qs, ...props.predictionData.qf];
- let max1 = getMaxValue(maxList) * 2;
- let min1 = getMinValue(maxList),
- max2 = getMaxValue(props.predictionData.rain) * 2;
- let min2 = getMinValue(props.predictionData.rain);
- const chart = echarts.init(prediction.value);
- var option;
- option = {
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- type: 'cross',
- animation: false,
- label: {
- backgroundColor: '#505765',
- },
- },
- formatter(params) {
- var relVal = params[0].name;
- for (var i = 0, l = params.length; i < l; i++) {
- console.log('tooltip数据值', params[i].value)
- //遍历出来的值一般是字符串,需要转换成数字,再进项tiFixed四舍五入
- // relVal += '<br/>' + params[i].marker + params[i].seriesName + ' : ' + params[i].value == '--'? Number(params[i].value) : params[i].value
- relVal += `<br/>${params[i].marker}${params[i].seriesName} : ${params[i].value == '--' ? params[i].value : Number(params[i].value)}`
- }
- return relVal;
- },
- },
- dataZoom: [
- {
- // 这个dataZoom组件,默认控制x轴。
- type: 'inside', // 这个 dataZoom 组件是 slider 型 dataZoom 组件
- },
- {
- // 这个dataZoom组件,也控制x轴。
- type: 'inside', // 这个 dataZoom 组件是 inside 型 dataZoom 组件
- },
- ],
- legend: {
- data: ['实测流量', '预测流量', '降雨'],
- textStyle: {
- fontSize: 12, //字体大小
- color: '#ffffff', //字体颜色
- },
- },
- xAxis: [
- {
- show: false,
- data: props.predictionData.name,
- axisLabel: {
- show: true,
- textStyle: {
- color: '#ffffff',
- },
- formatter: function (val) {
- var strs = val.split(''); //字符串数组
- var str = '';
- for (var i = 0, s; (s = strs[i++]);) {
- //遍历字符串数组
- if (i > 5 && i < 17) {
- str += s;
- }
- if (!(i % 10)) str += '\n'; //按需要求余
- }
- return str;
- },
- },
- },
- {
- data: props.predictionData.name,
- gridIndex: 1,
- axisLabel: {
- show: true,
- textStyle: {
- color: '#ffffff',
- },
- formatter: function (val) {
- var strs = val.split(''); //字符串数组
- var str = '';
- for (var i = 0, s; (s = strs[i++]);) {
- //遍历字符串数组
- if (i > 5 && i < 17) {
- str += s;
- }
- if (!(i % 10)) str += '\n'; //按需要求余
- }
- return str;
- },
- },
- },
- ],
- yAxis: [
- {
- position: 'right',
- name: '降雨(mm)',
- nameLocation: 'start',
- axisLabel: {
- textStyle: {
- color: '#ffffff',
- },
- formatter: function (value) {
- return value.toFixed(1) + '';
- },
- },
- nameTextStyle: {
- color: '#fff',
- fontSize: 12,
- },
- splitLine: {
- lineStyle: {
- type: 'dashed', //虚线
- color: '#484849',
- },
- },
- inverse: true,
- scale: true,
- },
- {
- // position: 'right',
- name: '流量(m³/s)',
- gridIndex: 1,
- axisLabel: {
- textStyle: {
- color: '#ffffff',
- },
- formatter: function (value) {
- if (value < 100) {
- return value.toPrecision(3)
- } else {
- return Number(value.toPrecision(3))
- }
- },
- },
- nameTextStyle: {
- color: '#fff',
- fontSize: 12,
- },
- formatter: function (value) {
- if (value < 100) {
- return value.toPrecision(3)
- } else {
- return Number(value.toPrecision(3))
- }
- },
- splitLine: {
- lineStyle: {
- type: 'dashed', //虚线
- color: '#484849',
- },
- },
- scale: true,
- min: function (value) {
- return value.min - value.min * 0.01;
- },
- max: function (value) {
- return value.max + value.max * 0.01;
- }
- },
- ],
- grid: [
- {
- bottom: '65%',
- left: '50',
- right: '50',
- },
- {
- top: '45%',
- left: '50',
- right: '50',
- bottom: '40',
- },
- ],
- series: [
- {
- name: '降雨',
- data: props.predictionData.rain,
- type: 'bar',
- barWidth: 5, // 设置每个柱子的宽度为40
- showSymbol: false,
- lineStyle: {
- width: 1,
- },
- itemStyle: {
- color: '#00CB98',
- },
- emphasis: {
- focus: 'series',
- },
- itemStyle: {
- normal: {
- color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
- offset: 0,
- color: 'rgba(14, 133, 225, 1)' // 0% 处的颜色
- }, {
- offset: 1,
- color: 'rgba(18, 196, 255, 1)' // 100% 处的颜色
- }], false),
- barBorderRadius: [30, 30, 30, 30],
- // shadowColor: 'rgba(0,160,221,1)',
- shadowBlur: 4,
- }
- },
- },
- {
- name: '实测流量',
- smooth: true,
- type: 'line',
- showSymbol: false,
- data: props.predictionData.qs,
- xAxisIndex: 1,
- yAxisIndex: 1,
- itemStyle: {
- color: `rgba(0, 243, 143, 1)`
- }
- },
- {
- name: '预测流量',
- type: 'line',
- showSymbol: false,
- smooth: true,
- data: props.predictionData.qf,
- xAxisIndex: 1,
- yAxisIndex: 1,
- lineStyle: {
- type: 'dashed', // 设置为虚线
- color: `rgba(255, 187, 41, 1)`
- }
- },
- ],
- };
- option && chart.setOption(option);
- }
- onMounted(() => {
- echarts1();
- });
- </script>
- <style lang="less" scoped>
- .main {
- margin-bottom: 10px;
- box-sizing: border-box;
- padding: 2px;
- border-radius: 0px 30px 0px 30px;
- // background-image: linear-gradient(200deg, rgba(40, 165, 255, 0.9) 9%, rgba(100, 255, 255, 0) 34%, rgba(40, 126, 255, 0) 66%, #28a5ff 100%);
- }
- .main_in {
- width: 100%;
- height: 100%;
- border-radius: 0px 30px 0px 30px;
- // background: rgba(6, 37, 70, 0.9);
- }
- .sub-title {
- cursor: pointer;
- text-align: left;
- padding-left: 20px;
- padding-top: 10px;
- padding-bottom: 0px;
- color: #dffeff;
- font-size: 18px;
- span {
- background: linear-gradient(0deg, #fbf70e 0%, #f4af10 100%);
- -webkit-background-clip: text;
- -webkit-text-fill-color: transparent;
- background-clip: text;
- text-fill-color: transparent;
- }
- }
- </style>
|