dataCurve.vue 6.7 KB

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