dataCurve.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <template>
  2. <view>
  3. <view class="all">
  4. <view class="chart">
  5. <view class="charts-box">
  6. <best-gauge :config="gaugeOption"></best-gauge>
  7. </view>
  8. <view class="charts-box">
  9. <best-gauge :config="gaugeOption2"></best-gauge>
  10. </view>
  11. </view>
  12. <view class="white">
  13. <view class="title1">
  14. <text class="param">空调排风温度变化</text>
  15. <view class="tiao"></view>
  16. </view>
  17. <view>
  18. <canvas canvas-id="canvasLineA" id="canvasLineA" class="charts" @touchmove="moveLineA"
  19. @touchend="moveLineA"></canvas>
  20. <!-- 画布,图表的HTML部分-->
  21. </view>
  22. </view>
  23. <view class="white1">
  24. <view class="title1">
  25. <text class="param">空调排风湿度变化</text>
  26. <view class="tiao"></view>
  27. </view>
  28. <view>
  29. <canvas canvas-id="canvasLineA11" id="canvasLineA11" class="charts" @touchmove="moveLineA11"
  30. @touchend="moveLineA11"></canvas>
  31. <!-- 画布,图表的HTML部分-->
  32. </view>
  33. </view>
  34. <view class="anniu">
  35. <image class="anniu" src="../../static/设备菜单/前往列表@2x.png" @tap="back"></image>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. //仪表盘组件
  42. import bestGauge from '@/components/best-gauge/best-gauge.vue'
  43. //引入u-charts组件
  44. import uCharts from '@/components/u-charts/u-charts.js'
  45. var _self; //用于全局使用this
  46. var _self11; //用于全局使用this
  47. var canvaLineA = null; //uCharts实例
  48. var canvaLineA11 = null; //uCharts实例
  49. export default {
  50. components: {
  51. bestGauge,
  52. },
  53. data() {
  54. let _width = uni.upx2px(350);
  55. return {
  56. formData: {
  57. WD_1: '',
  58. SD_1: '',
  59. QX: '2', //星期
  60. WD_SJ: '12',
  61. SD_SJ: '23',
  62. WD_SD: '34',
  63. SD_SD: '45',
  64. },
  65. cWidth: '',
  66. cHeight: '', //画布的宽高
  67. //仪表盘部分
  68. gaugeOption: { //定义参数
  69. id: 'gaugeId0',
  70. value: '',
  71. axisTickLength: 2 //该属性与axisTick互斥,存在axisTickLength并大于0,axisTick就无效
  72. },
  73. gaugeOption2: { //定义参数
  74. name: 'CK01排风湿度显示',
  75. id: 'gaugeId1',
  76. value: '',
  77. unit: '%',
  78. axisTickLength: 2 //该属性与axisTick互斥,存在axisTickLength并大于0,axisTick就无效
  79. },
  80. //折线图部分
  81. //温度
  82. data: { //数据
  83. categories: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"],
  84. series: [{
  85. name: "温度实际值",
  86. data: [40, 30, 36, 44, 34, 30, 22],
  87. }, {
  88. name: "温度设定值",
  89. data: [10, 25, 23, 33, 23, 35, 56],
  90. color: "#336633"
  91. }]
  92. },
  93. //湿度
  94. data11: { //数据
  95. categories11: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"],
  96. series11: [{
  97. name: "湿度实际值",
  98. data: [40, 30, 36, 44, 38, 34, 30],
  99. }, {
  100. name: "湿度设定值",
  101. data: [10, 25, 23, 33, 23, 35, 56],
  102. color: "red"
  103. }]
  104. },
  105. }
  106. },
  107. onLoad() {
  108. this.getWD_SJ()
  109. this.getSD_SJ()
  110. this.getWD_SD()
  111. this.getSD_SD()
  112. this.getWD_1()
  113. this.getSD_1()
  114. this.cWidth = uni.upx2px(702);
  115. this.cHeight = uni.upx2px(500); //设置宽高
  116. _self = this //声明this
  117. _self.showLineA("canvasLineA", _self.data); //触发执行函数
  118. _self11 = this //声明this
  119. _self11.showLineA11("canvasLineA11", _self11.data11); //触发执行函数
  120. },
  121. methods: {
  122. async getWD_SJ(e) {
  123. let vm = this;
  124. let url = uni.$api.deviceParam.detail;
  125. let data = {
  126. id: "292",
  127. };
  128. let res = await uni.$http.get(url, data);
  129. this.formData.WD_SJ = res.data.data.deviceParam.value;
  130. console.log(this.formData.WD_SJ);
  131. this.data.series[0].data[0] = this.formData.WD_SJ
  132. console.log("实际温度:" + this.data.series[0].data[0]);
  133. },
  134. async getSD_SJ(e) {
  135. let vm = this;
  136. let url = uni.$api.deviceParam.detail;
  137. let data = {
  138. id: "280",
  139. };
  140. let res = await uni.$http.get(url, data);
  141. this.formData.SD_SJ = res.data.data.deviceParam.value;
  142. console.log(this.formData.SD_SJ);
  143. this.data11.series11[0].data[0] = this.formData.SD_SJ
  144. console.log("实际湿度:" + this.data11.series11[0].data[0]);
  145. },
  146. async getWD_SD(e) {
  147. let vm = this;
  148. let url = uni.$api.deviceParam.detail;
  149. let data = {
  150. id: "296",
  151. };
  152. let res = await uni.$http.get(url, data);
  153. this.formData.WD_SD = res.data.data.deviceParam.value;
  154. console.log(this.formData.WD_SD);
  155. this.data.series[1].data[0] = this.formData.WD_SD
  156. console.log("设定温度:" + this.data.series[1].data[0]);
  157. },
  158. async getSD_SD(e) {
  159. let vm = this;
  160. var XQ = this.formData.QX;
  161. let url = uni.$api.deviceParam.detail;
  162. let data = {
  163. id: "231",
  164. };
  165. let res = await uni.$http.get(url, data);
  166. this.formData.SD_SD = res.data.data.deviceParam.value;
  167. console.log(this.formData.SD_SD);
  168. if (XQ == 1) {
  169. this.data11.series11[1].data[0] = this.formData.SD_SD
  170. console.log("周一设定湿度:" + this.data11.series11[1].data[0]);
  171. }
  172. if (XQ == 2) {
  173. this.data11.series11[1].data[1] = this.formData.SD_SD
  174. console.log("周二设定湿度:" + this.data11.series11[1].data[1]);
  175. }
  176. },
  177. back() {
  178. uni.navigateTo({
  179. url: '/pages/device/deviceInfo/deviceInfo'
  180. })
  181. },
  182. showLineA(canvasId, chartData) {
  183. canvaLineA = new uCharts({ //这些配置项的意思看这:https://www.kancloud.cn/qiun/ucharts/1172125
  184. $this: _self, //指针
  185. canvasId: canvasId, //id
  186. type: 'line', //类型
  187. colors: ['#F45E41'], //每一条的颜色
  188. fontSize: 14, //字体大小
  189. padding: [15, 15, 0, 15], //空白区域值
  190. legend: { //图例相关配置
  191. show: true,
  192. padding: 5,
  193. lineHeight: 11,
  194. margin: 0,
  195. },
  196. dataLabel: false, //显示数据标签内容值
  197. categories: chartData.categories, //数据类别
  198. series: chartData.series, //数据列表
  199. xAxis: { //X轴配置
  200. gridColor: '#CCCCCC', //X轴网格颜色
  201. gridType: 'dash', //X轴网格线型 'solid'为实线、'dash'为虚线`
  202. dashLength: 8, //X轴网格为虚线时,单段虚线长度
  203. },
  204. yAxis: { //y轴配置
  205. gridType: 'dash',
  206. gridColor: '#CCCCCC',
  207. dashLength: 8,
  208. },
  209. width: _self.cWidth, //canvas宽度,单位为px
  210. height: _self.cHeight, //canvas高度,单位为px
  211. extra: { //扩展配置
  212. line: {
  213. type: 'curve' //曲线 curve曲线,straight直线
  214. }
  215. }
  216. });
  217. },
  218. moveLineA(e) {
  219. canvaLineA.showToolTip(e, { //详情框
  220. format: function(item, category) {
  221. return category + ' ' + item.name + ':' + item.data + '℃'
  222. }
  223. });
  224. },
  225. //湿度
  226. showLineA11(canvasId, chartData) {
  227. canvaLineA11 = new uCharts({ //这些配置项的意思看这:https://www.kancloud.cn/qiun/ucharts/1172125
  228. $this: _self11, //指针
  229. canvasId: canvasId, //id
  230. type: 'line', //类型
  231. colors: ['#007AFF'], //每一条的颜色
  232. fontSize: 14, //字体大小
  233. padding: [15, 15, 0, 15], //空白区域值
  234. legend: { //图例相关配置
  235. show: true,
  236. padding: 5,
  237. lineHeight: 11,
  238. margin: 0,
  239. },
  240. dataLabel: false, //显示数据标签内容值
  241. categories: chartData.categories11, //数据类别
  242. series: chartData.series11, //数据列表
  243. xAxis: { //X轴配置
  244. gridColor: '#CCCCCC', //X轴网格颜色
  245. gridType: 'dash', //X轴网格线型 'solid'为实线、'dash'为虚线`
  246. dashLength: 8, //X轴网格为虚线时,单段虚线长度
  247. },
  248. yAxis: { //y轴配置
  249. gridType: 'dash',
  250. gridColor: '#CCCCCC',
  251. dashLength: 8,
  252. },
  253. width: _self11.cWidth, //canvas宽度,单位为px
  254. height: _self11.cHeight, //canvas高度,单位为px
  255. extra: { //扩展配置
  256. line: {
  257. type: 'curve' //曲线 curve曲线,straight直线
  258. }
  259. }
  260. });
  261. },
  262. moveLineA11(e) {
  263. canvaLineA11.showToolTip(e, { //详情框
  264. format: function(item, category) {
  265. return category + ' ' + item.name + ':' + item.data + '%'
  266. }
  267. });
  268. },
  269. async getWD_1(e) {
  270. let vm = this;
  271. let url = uni.$api.deviceParam.detail;
  272. let data = {
  273. id: "207",
  274. };
  275. let res = await uni.$http.get(url, data);
  276. console.log('form发生了submit事件')
  277. this.gaugeOption.value = res.data.data.deviceParam.value;
  278. },
  279. async getSD_1(e) {
  280. let vm = this;
  281. let url = uni.$api.deviceParam.detail;
  282. let data = {
  283. id: "293",
  284. };
  285. let res = await uni.$http.get(url, data);
  286. console.log('form发生了submit事件')
  287. this.gaugeOption2.value = res.data.data.deviceParam.value;
  288. },
  289. }
  290. }
  291. </script>
  292. <style>
  293. .anniu {
  294. width: 116rpx;
  295. height: 116rpx;
  296. float: right;
  297. margin-top: 20rpx;
  298. }
  299. .charts {
  300. margin-top: 60rpx;
  301. width: 702rpx;
  302. height: 500rpx;
  303. background-color: #FFFFFF;
  304. }
  305. .title1 {
  306. display: flex;
  307. flex-direction: column;
  308. align-items: center;
  309. }
  310. .tiao {
  311. width: 60px;
  312. height: 3px;
  313. margin-top: 20rpx;
  314. background: #007AFF;
  315. }
  316. .param {
  317. font-size: 38rpx;
  318. font-weight: 550;
  319. margin-top: 40rpx;
  320. }
  321. .white {
  322. width: 702rpx;
  323. height: 720rpx;
  324. margin-left: 24rpx;
  325. background-color: white;
  326. margin-top: 28rpx;
  327. border-radius: 10rpx;
  328. }
  329. .white1 {
  330. width: 702rpx;
  331. height: 720rpx;
  332. margin-left: 24rpx;
  333. background-color: white;
  334. margin-top: 28rpx;
  335. border-radius: 10rpx;
  336. }
  337. .chart {
  338. font-size: 26rpx;
  339. height: 300px;
  340. /* background:white; */
  341. background: rgb(30, 130, 250);
  342. display: flex;
  343. flex-direction: row;
  344. align-items: center;
  345. justify-content: center;
  346. }
  347. .charts-box {
  348. margin-left: 8rpx;
  349. margin-right: 8rpx;
  350. }
  351. </style>