predictionA.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <div class="main">
  3. <div class="main_in">
  4. <div class="sub-title" @click="jump">
  5. <span>{{ title.pageTitle }}&nbsp;</span>{{ title.titleText }}
  6. </div>
  7. <div>
  8. <div ref="prediction" style="width: 100%; height: 376px"></div>
  9. </div>
  10. </div>
  11. </div>
  12. </template>
  13. <script lang="ts" setup>
  14. import { toRef, ref, getCurrentInstance, onMounted } from 'vue';
  15. import eventBus from '/@/utils/eventBus';
  16. const jump = () => {
  17. eventBus.emit('mapjump', props.title);
  18. };
  19. let activeKey = ref('1');
  20. //组件传参
  21. const props = defineProps({
  22. title: { type: Object },
  23. nodeId: { type: String },
  24. predictionData: {
  25. type: Object,
  26. default: () => {
  27. return {};
  28. },
  29. },
  30. });
  31. let datas = toRef(props, 'predictionData');
  32. // // 计算最大值
  33. function getMaxValue(arr) {
  34. const max = Math.max(...arr);
  35. // 这样处理是为了不让最大值刚好到坐标轴最顶部
  36. return Math.ceil(max / 9.5) * 10;
  37. }
  38. // 计算最小值
  39. function getMinValue(arr) {
  40. const min = Math.min(...arr);
  41. // 这样处理是为了不让最大值刚好到坐标轴最底部
  42. return Math.floor(min / 12) * 10;
  43. }
  44. // 引入图表插件
  45. const { proxy } = getCurrentInstance();
  46. const echarts = proxy.$echarts;
  47. let prediction = ref(null);
  48. function echarts1() {
  49. let maxList = [...props.predictionData.qs, ...props.predictionData.qf];
  50. let max1 = getMaxValue(maxList) * 2;
  51. let min1 = getMinValue(maxList),
  52. max2 = getMaxValue(props.predictionData.rain) * 2;
  53. let min2 = getMinValue(props.predictionData.rain);
  54. const chart = echarts.init(prediction.value);
  55. var option;
  56. option = {
  57. tooltip: {
  58. trigger: 'axis',
  59. axisPointer: {
  60. type: 'cross',
  61. animation: false,
  62. label: {
  63. backgroundColor: '#505765',
  64. },
  65. },
  66. formatter(params) {
  67. var relVal = params[0].name;
  68. for (var i = 0, l = params.length; i < l; i++) {
  69. console.log('tooltip数据值', params[i].value)
  70. //遍历出来的值一般是字符串,需要转换成数字,再进项tiFixed四舍五入
  71. // relVal += '<br/>' + params[i].marker + params[i].seriesName + ' : ' + params[i].value == '--'? Number(params[i].value) : params[i].value
  72. relVal += `<br/>${params[i].marker}${params[i].seriesName} : ${params[i].value == '--' ? params[i].value : Number(params[i].value)}`
  73. }
  74. return relVal;
  75. },
  76. },
  77. dataZoom: [
  78. {
  79. // 这个dataZoom组件,默认控制x轴。
  80. type: 'inside', // 这个 dataZoom 组件是 slider 型 dataZoom 组件
  81. },
  82. {
  83. // 这个dataZoom组件,也控制x轴。
  84. type: 'inside', // 这个 dataZoom 组件是 inside 型 dataZoom 组件
  85. },
  86. ],
  87. legend: {
  88. data: ['实测流量', '预测流量', '降雨'],
  89. textStyle: {
  90. fontSize: 12, //字体大小
  91. color: '#ffffff', //字体颜色
  92. },
  93. },
  94. xAxis: [
  95. {
  96. show: false,
  97. data: props.predictionData.name,
  98. axisLabel: {
  99. show: true,
  100. textStyle: {
  101. color: '#ffffff',
  102. },
  103. formatter: function (val) {
  104. var strs = val.split(''); //字符串数组
  105. var str = '';
  106. for (var i = 0, s; (s = strs[i++]);) {
  107. //遍历字符串数组
  108. if (i > 5 && i < 17) {
  109. str += s;
  110. }
  111. if (!(i % 10)) str += '\n'; //按需要求余
  112. }
  113. return str;
  114. },
  115. },
  116. },
  117. {
  118. data: props.predictionData.name,
  119. gridIndex: 1,
  120. axisLabel: {
  121. show: true,
  122. textStyle: {
  123. color: '#ffffff',
  124. },
  125. formatter: function (val) {
  126. var strs = val.split(''); //字符串数组
  127. var str = '';
  128. for (var i = 0, s; (s = strs[i++]);) {
  129. //遍历字符串数组
  130. if (i > 5 && i < 17) {
  131. str += s;
  132. }
  133. if (!(i % 10)) str += '\n'; //按需要求余
  134. }
  135. return str;
  136. },
  137. },
  138. },
  139. ],
  140. yAxis: [
  141. {
  142. position: 'right',
  143. name: '降雨(mm)',
  144. nameLocation: 'start',
  145. axisLabel: {
  146. textStyle: {
  147. color: '#ffffff',
  148. },
  149. formatter: function (value) {
  150. return value.toFixed(2) + '';
  151. },
  152. },
  153. nameTextStyle: {
  154. color: '#fff',
  155. fontSize: 12,
  156. },
  157. splitLine: {
  158. lineStyle: {
  159. type: 'dashed', //虚线
  160. color: '#484849',
  161. },
  162. },
  163. inverse: true,
  164. scale: true,
  165. },
  166. {
  167. // position: 'right',
  168. name: '流量(m³/s)',
  169. gridIndex: 1,
  170. axisLabel: {
  171. textStyle: {
  172. color: '#ffffff',
  173. },
  174. formatter: function (value) {
  175. return value + '';
  176. },
  177. },
  178. nameTextStyle: {
  179. color: '#fff',
  180. fontSize: 12,
  181. },
  182. splitLine: {
  183. lineStyle: {
  184. type: 'dashed', //虚线
  185. color: '#484849',
  186. },
  187. },
  188. scale: true,
  189. min: function (value) {
  190. return value.min - value.min * 0.1;
  191. },
  192. max: function (value) {
  193. return value.max + value.max * 0.1;
  194. }
  195. },
  196. ],
  197. grid: [
  198. {
  199. bottom: '65%',
  200. left: '50',
  201. right: '50',
  202. },
  203. {
  204. top: '45%',
  205. left: '50',
  206. right: '50',
  207. bottom: '40',
  208. },
  209. ],
  210. series: [
  211. {
  212. name: '降雨',
  213. data: props.predictionData.rain,
  214. type: 'bar',
  215. barWidth: 5, // 设置每个柱子的宽度为40
  216. showSymbol: false,
  217. lineStyle: {
  218. width: 1,
  219. },
  220. itemStyle: {
  221. color: '#00CB98',
  222. },
  223. emphasis: {
  224. focus: 'series',
  225. },
  226. },
  227. {
  228. name: '实测流量',
  229. smooth: true,
  230. type: 'line',
  231. showSymbol: false,
  232. data: props.predictionData.qs,
  233. xAxisIndex: 1,
  234. yAxisIndex: 1,
  235. },
  236. {
  237. name: '预测流量',
  238. type: 'line',
  239. showSymbol: false,
  240. smooth: true,
  241. data: props.predictionData.qf,
  242. xAxisIndex: 1,
  243. yAxisIndex: 1,
  244. },
  245. ],
  246. };
  247. option && chart.setOption(option);
  248. }
  249. onMounted(() => {
  250. echarts1();
  251. });
  252. </script>
  253. <style lang="less" scoped>
  254. .main {
  255. margin-bottom: 10px;
  256. box-sizing: border-box;
  257. padding: 2px;
  258. border-radius: 0px 30px 0px 30px;
  259. 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%);
  260. }
  261. .main_in {
  262. width: 100%;
  263. height: 100%;
  264. border-radius: 0px 30px 0px 30px;
  265. background: rgba(6, 37, 70, 0.9);
  266. }
  267. .sub-title {
  268. cursor: pointer;
  269. text-align: left;
  270. padding-left: 20px;
  271. padding-top: 10px;
  272. padding-bottom: 0px;
  273. color: #dffeff;
  274. font-size: 18px;
  275. span {
  276. background: linear-gradient(0deg, #fbf70e 0%, #f4af10 100%);
  277. -webkit-background-clip: text;
  278. -webkit-text-fill-color: transparent;
  279. background-clip: text;
  280. text-fill-color: transparent;
  281. }
  282. }
  283. </style>