YuzhiCurve.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <template>
  2. <div class="yuzhi-curve-module">
  3. <common-title title="预制曲线"></common-title>
  4. <div class="visualization-common-border">
  5. <div ref="yuzhiCurve" class="h100"></div>
  6. </div>
  7. </div>
  8. </template>
  9. <script>
  10. import * as echarts from "echarts"
  11. import commonTitle from '../components/commonTitle.vue'
  12. import { setMax } from "../components/common.js";
  13. var moniData = [
  14. {
  15. circname:"内部循环1",
  16. begintime: '00:00',
  17. endtime: '00:40',
  18. sections:[
  19. {secname:0,temperature:'50.0',humidity:'78.0',time:"00:00"},
  20. {secname:1,temperature:'40.0',humidity:'78.0',time:"00:20"},
  21. {secname:2,temperature:'40.0',humidity:'58.0',time:"00:40"}
  22. ],
  23. },
  24. {
  25. circname:"内部循环2",
  26. begintime: '00:50',
  27. endtime: '01:10',
  28. sections:[
  29. {secname:4,temperature:'40.0',humidity:'-58.0',time:"00:50"},
  30. {secname:5,temperature:'60.0',humidity:'-88.0',time:"01:10"}
  31. ]
  32. },
  33. ]
  34. export default {
  35. components: { commonTitle },
  36. name: '',
  37. props: {
  38. data: {
  39. type: Array,
  40. default: function(){
  41. return [] // 使用工厂函数返回默认值
  42. }
  43. }
  44. },
  45. data () {
  46. return {
  47. chooseXunhuan: {
  48. circname: '',
  49. begintime: '',
  50. endtime: ''
  51. },
  52. uEcharts: null,
  53. uOption: null,
  54. legendData: [
  55. { name: '辐射强度值', value: 9000 },
  56. { name: '温度实值', value: 50 },
  57. { name: '湿度实值', value: 60.3 },
  58. ],
  59. fusheData: [],
  60. wenduData: [],
  61. shiduData: [],
  62. timeData: [],
  63. // fusheData: [150, 230, 224, 218, 135, 147, 260],
  64. // wenduData: [50, 60, 60, 70, 50, 50, 60],
  65. // shiduData: [40, 70, 70, 40, 40, 50, 50],
  66. // timeData: ['08:00', '09:00', '10:00', '11:00', '12:00', '13:00', '14:00']
  67. }
  68. },
  69. watch: {
  70. data: {
  71. handler(newValue, oldValue){
  72. console.log('预制曲线', newValue, oldValue)
  73. this.refreshData(newValue)
  74. },
  75. // immediate: true,
  76. deep: true
  77. },
  78. 'chooseXunhuan.circname': {
  79. handler(newValue, oldValue){
  80. if(newValue){
  81. this.changeXunhuan(newValue)
  82. }
  83. },
  84. // immediate: true,
  85. deep: true
  86. },
  87. },
  88. created () {
  89. // this.changeData(moniData)
  90. },
  91. mounted () {
  92. this.$nextTick(() => {
  93. this.initYuzhiCurve()
  94. })
  95. },
  96. methods: {
  97. initYuzhiCurve(){
  98. var _this = this
  99. var maxa = Math.max.apply(null, this.fusheData)
  100. var maxb = Math.max.apply(null, [...this.wenduData, ...this.shiduData])
  101. this.uEcharts = echarts.init(this.$refs.yuzhiCurve);
  102. this.uOption = {
  103. color: ['#0102c8', '#cfa809', '#49e4e9'], // legend对应颜色
  104. grid: {
  105. top: '80',
  106. left: '46',
  107. bottom: '40'
  108. },
  109. tooltip: {
  110. trigger: 'axis',
  111. },
  112. xAxis: {
  113. type: 'category',
  114. axisTick: { show: false }, // 横坐标刻度
  115. boundaryGap: false, // 坐标轴两边留白(刻度跟数据对应)
  116. axisLine: { // 横坐标线样式
  117. lineStyle: {
  118. color: 'rgba(255,255,255,.1)',
  119. },
  120. },
  121. axisLabel: {
  122. textStyle: { // 坐标轴文字
  123. color: '#fff'
  124. }
  125. },
  126. data: _this.timeData
  127. },
  128. yAxis: [
  129. {
  130. type: 'value',
  131. axisLabel: { // 纵坐标样式
  132. textStyle: {
  133. color: '#fff',
  134. }
  135. },
  136. splitLine: { // 网格线
  137. show: true, // 是否显示
  138. lineStyle: { // 网格线样式
  139. color: 'rgba(255,255,255,.1)', // 网格线颜色
  140. width: 1, //网格线的加粗程度
  141. // type: 'dashed' // 网格线类型 dashed:虚线
  142. }
  143. },
  144. name: '光照强度W/㎡', // 刻度
  145. nameTextStyle: {
  146. color: '#fff',
  147. padding: [0, 0, 0, 20],
  148. },
  149. alignTicks: true,
  150. // min: 0,
  151. // max: setMax(maxa),
  152. // interval: setMax(maxa) / 5,
  153. },
  154. {
  155. type: 'value',
  156. axisLabel: { // 纵坐标样式
  157. textStyle: {
  158. color: '#fff',
  159. }
  160. },
  161. splitLine: { // 网格线
  162. show: true, // 是否显示
  163. lineStyle: { // 网格线样式
  164. color: 'rgba(255,255,255,.1)', // 网格线颜色
  165. width: 1, //网格线的加粗程度
  166. // type: 'dashed' // 网格线类型 dashed:虚线
  167. }
  168. },
  169. name: '温湿度值/℃/%', // 刻度
  170. nameTextStyle: {
  171. color: '#fff',
  172. // padding: [0, 0, 0, 20],
  173. },
  174. alignTicks: true,
  175. // min: 0,
  176. // max: setMax(maxb),
  177. // interval: setMax(maxb) / 5,
  178. },
  179. ],
  180. legend: {
  181. icon: "roundRect", // 样式改为方形rect,改为圆角方形roundRect
  182. itemWidth: 14, // 宽度
  183. itemHeight: 6, // 高度
  184. textStyle: {
  185. color: '#fff',
  186. fontSize: 11
  187. },
  188. top: '15',
  189. // 使用回调函数:加上数值方法
  190. // formatter: function (name) {
  191. // console.log(name)
  192. // var currentObj = _this.legendData.find(item => item.name === name)
  193. // return name + ':' + currentObj.value;
  194. // },
  195. data: _this.legendData.map(item => item.name),
  196. },
  197. series: [
  198. {
  199. name: '辐射强度值',
  200. type: 'line',
  201. // symbol: 'circle',
  202. // symbolSize: 2,
  203. showSymbol: false, // 只有在 tooltip hover 的时候显示symbol
  204. // itemStyle: { // symbol样式
  205. // normal: {
  206. // color: 'rgb(255, 255, 255)',
  207. // borderColor: 'rgba(255, 255, 255, 0.2)', // symbol边框颜色
  208. // borderWidth: 12 // symbol边框宽度
  209. // }
  210. // },
  211. lineStyle: { // 线条样式
  212. normal: {
  213. width: 2,
  214. color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [ // 颜色渐变
  215. {
  216. offset: 0,
  217. color: 'rgb(1, 2, 200, 0)'
  218. },
  219. {
  220. offset: 0.5,
  221. color: 'rgb(1, 2, 200)'
  222. },
  223. {
  224. offset: 1,
  225. color: 'rgb(1, 2, 200, 0)'
  226. }
  227. ])
  228. }
  229. },
  230. data: _this.fusheData,
  231. },
  232. {
  233. name: '温度实值',
  234. type: 'line',
  235. yAxisIndex: 1, // 关联第几个y轴
  236. showSymbol: false,
  237. lineStyle: { // 线条样式
  238. normal: {
  239. width: 2,
  240. color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [ // 颜色渐变
  241. {
  242. offset: 0,
  243. color: 'rgba(207, 168, 9, .5)'
  244. },
  245. {
  246. offset: 0.5,
  247. color: 'rgb(207, 168, 9)'
  248. },
  249. {
  250. offset: 1,
  251. color: 'rgba(207, 168, 9, .5)'
  252. }
  253. ])
  254. }
  255. },
  256. markArea: {
  257. itemStyle: {
  258. color: 'rgba(255, 173, 177, 0.4)'
  259. },
  260. data: [
  261. [
  262. {
  263. name: _this.chooseXunhuan.circname,
  264. xAxis: _this.chooseXunhuan.begintime
  265. },
  266. {
  267. xAxis: _this.chooseXunhuan.endtime
  268. }
  269. ],
  270. ]
  271. },
  272. data: _this.wenduData,
  273. },
  274. {
  275. name: '湿度实值',
  276. type: 'line',
  277. yAxisIndex: 1, // 关联第几个y轴
  278. showSymbol: false,
  279. lineStyle: { // 线条样式
  280. normal: {
  281. width: 2,
  282. color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [ // 颜色渐变
  283. {
  284. offset: 0,
  285. color: 'rgba(73, 228, 233, .5)'
  286. },
  287. {
  288. offset: 0.5,
  289. color: 'rgb(73, 228, 233)'
  290. },
  291. {
  292. offset: 1,
  293. color: 'rgba(73, 228, 233, .5)'
  294. }
  295. ])
  296. }
  297. },
  298. data: _this.shiduData,
  299. }
  300. ]
  301. };
  302. this.uOption && this.uEcharts.setOption(this.uOption)
  303. window.addEventListener("resize", ()=>{
  304. this.uEcharts.resize();
  305. });
  306. },
  307. // 数据刷新时
  308. refreshData(data){
  309. console.log('预制曲线数据', data)
  310. this.wenduData = []
  311. this.shiduData = []
  312. this.timeData = []
  313. data.forEach(element => {
  314. var itemWenduArr = element.sections.map(item => {
  315. return item.temperature
  316. })
  317. var itemShiduArr = element.sections.map(item => {
  318. return item.humidity
  319. })
  320. var itemTimeArr = element.sections.map(item => {
  321. return item.time
  322. })
  323. this.wenduData = [...this.wenduData, ...itemWenduArr]
  324. this.shiduData = [...this.shiduData, ...itemShiduArr]
  325. this.timeData = [...this.timeData, ...itemTimeArr]
  326. // console.log(this.wenduData)
  327. // console.log(this.shiduData)
  328. });
  329. var _this = this
  330. this.uOption.xAxis.data = this.timeData
  331. this.uOption.series.forEach(item => {
  332. switch (item.name) {
  333. case '辐射强度值':
  334. item.data = _this.fusheData
  335. break;
  336. case '温度实值':
  337. item.data = _this.wenduData
  338. break;
  339. case '湿度实值':
  340. item.data = _this.shiduData
  341. break;
  342. default:
  343. break;
  344. }
  345. })
  346. // this.uEcharts.clear()
  347. this.uEcharts.setOption(this.uOption, true);
  348. // this.uEcharts.setOption({
  349. // xAxis: {
  350. // data: _this.timeData
  351. // },
  352. // series: [
  353. // {
  354. // name: '辐射强度值',
  355. // data: _this.fusheData
  356. // },
  357. // {
  358. // name: '温度实值',
  359. // data: _this.wenduData
  360. // },
  361. // {
  362. // name: '湿度实值',
  363. // data: _this.shiduData
  364. // },
  365. // ]
  366. // });
  367. },
  368. // 点击循环改变高亮
  369. changeXunhuan(data){
  370. var value = this.data.find(item => item.circname === data)
  371. console.log(value)
  372. if(value){
  373. this.chooseXunhuan.circname = value.circname
  374. this.chooseXunhuan.begintime = value.begintime
  375. this.chooseXunhuan.endtime = value.endtime
  376. } else {
  377. this.chooseXunhuan.circname = ''
  378. this.chooseXunhuan.begintime = ''
  379. this.chooseXunhuan.endtime = ''
  380. }
  381. console.log(this.chooseXunhuan)
  382. var _this = this
  383. this.uEcharts.setOption({
  384. series: [
  385. {
  386. name: '温度实值',
  387. markArea: {
  388. itemStyle: {
  389. color: 'rgba(67, 172, 225, 0.4)'
  390. // color: 'rgba(255, 173, 177, 0.4)'
  391. },
  392. data: [
  393. [
  394. {
  395. name: _this.chooseXunhuan.circname,
  396. xAxis: _this.chooseXunhuan.begintime
  397. },
  398. {
  399. xAxis: _this.chooseXunhuan.endtime
  400. }
  401. ],
  402. ]
  403. },
  404. },
  405. ]
  406. });
  407. },
  408. }
  409. }
  410. </script>
  411. <style scoped>
  412. @import '~@/assets/less/uStyle.less';
  413. </style>
  414. <style lang="less">
  415. .yuzhi-curve-module{
  416. width: 100%;
  417. height: 100%;
  418. }
  419. </style>