dataCurve.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. },
  60. cWidth: '',
  61. cHeight: '', //画布的宽高
  62. //仪表盘部分
  63. gaugeOption: { //定义参数
  64. id: 'gaugeId0',
  65. value: '',
  66. axisTickLength: 2 //该属性与axisTick互斥,存在axisTickLength并大于0,axisTick就无效
  67. },
  68. gaugeOption2: { //定义参数
  69. name: 'CK01排风湿度显示',
  70. id: 'gaugeId1',
  71. value: '',
  72. unit: '%',
  73. axisTickLength: 2 //该属性与axisTick互斥,存在axisTickLength并大于0,axisTick就无效
  74. },
  75. //折线图部分
  76. //温度
  77. data: { //数据
  78. categories: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"],
  79. series: [{
  80. name: "温度",
  81. data: [40, 30, 36, 44, 34, 30, 22],
  82. }]
  83. },
  84. //湿度
  85. data11: { //数据
  86. categories11: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"],
  87. series11: [{
  88. name: "湿度",
  89. data: [40, 30, 36, 44, 38, 34, 30],
  90. }]
  91. },
  92. }
  93. },
  94. onLoad() {
  95. this.getWD_1()
  96. this.getSD_1()
  97. this.cWidth = uni.upx2px(702);
  98. this.cHeight = uni.upx2px(500); //设置宽高
  99. _self = this //声明this
  100. _self.showLineA("canvasLineA", _self.data); //触发执行函数
  101. _self11 = this //声明this
  102. _self11.showLineA11("canvasLineA11", _self11.data11); //触发执行函数
  103. },
  104. methods: {
  105. back() {
  106. uni.navigateTo({
  107. url: '/pages/device/deviceInfo/deviceInfo'
  108. })
  109. },
  110. showLineA(canvasId, chartData) {
  111. canvaLineA = new uCharts({ //这些配置项的意思看这:https://www.kancloud.cn/qiun/ucharts/1172125
  112. $this: _self, //指针
  113. canvasId: canvasId, //id
  114. type: 'line', //类型
  115. colors: ['#F45E41'], //每一条的颜色
  116. fontSize: 14, //字体大小
  117. padding: [15, 15, 0, 15], //空白区域值
  118. legend: { //图例相关配置
  119. show: true,
  120. padding: 5,
  121. lineHeight: 11,
  122. margin: 0,
  123. },
  124. dataLabel: false, //显示数据标签内容值
  125. categories: chartData.categories, //数据类别
  126. series: chartData.series, //数据列表
  127. xAxis: { //X轴配置
  128. gridColor: '#CCCCCC', //X轴网格颜色
  129. gridType: 'dash', //X轴网格线型 'solid'为实线、'dash'为虚线`
  130. dashLength: 8, //X轴网格为虚线时,单段虚线长度
  131. },
  132. yAxis: { //y轴配置
  133. gridType: 'dash',
  134. gridColor: '#CCCCCC',
  135. dashLength: 8,
  136. },
  137. width: _self.cWidth, //canvas宽度,单位为px
  138. height: _self.cHeight, //canvas高度,单位为px
  139. extra: { //扩展配置
  140. line: {
  141. type: 'curve' //曲线 curve曲线,straight直线
  142. }
  143. }
  144. });
  145. },
  146. moveLineA(e) {
  147. canvaLineA.showToolTip(e, { //详情框
  148. format: function(item, category) {
  149. return category + ' ' + item.name + ':' + item.data + '℃'
  150. }
  151. });
  152. },
  153. //湿度
  154. showLineA11(canvasId, chartData) {
  155. canvaLineA11 = new uCharts({ //这些配置项的意思看这:https://www.kancloud.cn/qiun/ucharts/1172125
  156. $this: _self11, //指针
  157. canvasId: canvasId, //id
  158. type: 'line', //类型
  159. colors: ['#007AFF'], //每一条的颜色
  160. fontSize: 14, //字体大小
  161. padding: [15, 15, 0, 15], //空白区域值
  162. legend: { //图例相关配置
  163. show: true,
  164. padding: 5,
  165. lineHeight: 11,
  166. margin: 0,
  167. },
  168. dataLabel: false, //显示数据标签内容值
  169. categories: chartData.categories11, //数据类别
  170. series: chartData.series11, //数据列表
  171. xAxis: { //X轴配置
  172. gridColor: '#CCCCCC', //X轴网格颜色
  173. gridType: 'dash', //X轴网格线型 'solid'为实线、'dash'为虚线`
  174. dashLength: 8, //X轴网格为虚线时,单段虚线长度
  175. },
  176. yAxis: { //y轴配置
  177. gridType: 'dash',
  178. gridColor: '#CCCCCC',
  179. dashLength: 8,
  180. },
  181. width: _self11.cWidth, //canvas宽度,单位为px
  182. height: _self11.cHeight, //canvas高度,单位为px
  183. extra: { //扩展配置
  184. line: {
  185. type: 'curve' //曲线 curve曲线,straight直线
  186. }
  187. }
  188. });
  189. },
  190. moveLineA11(e) {
  191. canvaLineA11.showToolTip(e, { //详情框
  192. format: function(item, category) {
  193. return category + ' ' + item.name + ':' + item.data + '%'
  194. }
  195. });
  196. },
  197. async getWD_1(e) {
  198. let vm = this;
  199. let url = uni.$api.deviceParam.detail;
  200. let data = {
  201. id: "206",
  202. };
  203. let res = await uni.$http.get(url, data);
  204. console.log('form发生了submit事件')
  205. this.gaugeOption.value = res.data.data.deviceParam.value;
  206. },
  207. async getSD_1(e) {
  208. let vm = this;
  209. let url = uni.$api.deviceParam.detail;
  210. let data = {
  211. id: "284",
  212. };
  213. let res = await uni.$http.get(url, data);
  214. console.log('form发生了submit事件')
  215. this.gaugeOption2.value = res.data.data.deviceParam.value;
  216. },
  217. }
  218. }
  219. </script>
  220. <style>
  221. .anniu {
  222. width: 116rpx;
  223. height: 116rpx;
  224. float: right;
  225. margin-top: 20rpx;
  226. }
  227. .charts {
  228. margin-top: 60rpx;
  229. width: 702rpx;
  230. height: 500rpx;
  231. background-color: #FFFFFF;
  232. }
  233. .title1 {
  234. display: flex;
  235. flex-direction: column;
  236. align-items: center;
  237. }
  238. .tiao {
  239. width: 60px;
  240. height: 3px;
  241. margin-top: 20rpx;
  242. background: #007AFF;
  243. }
  244. .param {
  245. font-size: 38rpx;
  246. font-weight: 550;
  247. margin-top: 40rpx;
  248. }
  249. .white {
  250. width: 702rpx;
  251. height: 720rpx;
  252. margin-left: 24rpx;
  253. background-color: white;
  254. margin-top: 28rpx;
  255. border-radius: 10rpx;
  256. }
  257. .white1 {
  258. width: 702rpx;
  259. height: 720rpx;
  260. margin-left: 24rpx;
  261. background-color: white;
  262. margin-top: 28rpx;
  263. border-radius: 10rpx;
  264. }
  265. .chart {
  266. font-size: 26rpx;
  267. height: 300px;
  268. /* background:white; */
  269. background: rgb(30, 130, 250);
  270. display: flex;
  271. flex-direction: row;
  272. align-items: center;
  273. justify-content: center;
  274. }
  275. .charts-box {
  276. margin-left: 8rpx;
  277. margin-right: 8rpx;
  278. }
  279. </style>