dataCurve.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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"></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. showLineA(canvasId, chartData) {
  100. canvaLineA = new uCharts({ //这些配置项的意思看这:https://www.kancloud.cn/qiun/ucharts/1172125
  101. $this: _self, //指针
  102. canvasId: canvasId, //id
  103. type: 'line', //类型
  104. colors: ['#F45E41'], //每一条的颜色
  105. fontSize: 14, //字体大小
  106. padding: [15, 15, 0, 15], //空白区域值
  107. legend: { //图例相关配置
  108. show: true,
  109. padding: 5,
  110. lineHeight: 11,
  111. margin: 0,
  112. },
  113. dataLabel: false, //显示数据标签内容值
  114. categories: chartData.categories, //数据类别
  115. series: chartData.series, //数据列表
  116. xAxis: { //X轴配置
  117. gridColor: '#CCCCCC', //X轴网格颜色
  118. gridType: 'dash', //X轴网格线型 'solid'为实线、'dash'为虚线`
  119. dashLength: 8, //X轴网格为虚线时,单段虚线长度
  120. },
  121. yAxis: { //y轴配置
  122. gridType: 'dash',
  123. gridColor: '#CCCCCC',
  124. dashLength: 8,
  125. },
  126. width: _self.cWidth, //canvas宽度,单位为px
  127. height: _self.cHeight, //canvas高度,单位为px
  128. extra: { //扩展配置
  129. line: {
  130. type: 'curve' //曲线 curve曲线,straight直线
  131. }
  132. }
  133. });
  134. },
  135. moveLineA(e) {
  136. canvaLineA.showToolTip(e, { //详情框
  137. format: function(item, category) {
  138. return category + ' ' + item.name + ':' + item.data + '℃'
  139. }
  140. });
  141. },
  142. //湿度
  143. showLineA11(canvasId, chartData) {
  144. canvaLineA11 = new uCharts({ //这些配置项的意思看这:https://www.kancloud.cn/qiun/ucharts/1172125
  145. $this: _self11, //指针
  146. canvasId: canvasId, //id
  147. type: 'line', //类型
  148. colors: ['#007AFF'], //每一条的颜色
  149. fontSize: 14, //字体大小
  150. padding: [15, 15, 0, 15], //空白区域值
  151. legend: { //图例相关配置
  152. show: true,
  153. padding: 5,
  154. lineHeight: 11,
  155. margin: 0,
  156. },
  157. dataLabel: false, //显示数据标签内容值
  158. categories: chartData.categories11, //数据类别
  159. series: chartData.series11, //数据列表
  160. xAxis: { //X轴配置
  161. gridColor: '#CCCCCC', //X轴网格颜色
  162. gridType: 'dash', //X轴网格线型 'solid'为实线、'dash'为虚线`
  163. dashLength: 8, //X轴网格为虚线时,单段虚线长度
  164. },
  165. yAxis: { //y轴配置
  166. gridType: 'dash',
  167. gridColor: '#CCCCCC',
  168. dashLength: 8,
  169. },
  170. width: _self11.cWidth, //canvas宽度,单位为px
  171. height: _self11.cHeight, //canvas高度,单位为px
  172. extra: { //扩展配置
  173. line: {
  174. type: 'curve' //曲线 curve曲线,straight直线
  175. }
  176. }
  177. });
  178. },
  179. moveLineA11(e) {
  180. canvaLineA11.showToolTip(e, { //详情框
  181. format: function(item, category) {
  182. return category + ' ' + item.name + ':' + item.data + '%'
  183. }
  184. });
  185. },
  186. }
  187. }
  188. </script>
  189. <style>
  190. .anniu {
  191. width: 116rpx;
  192. height: 116rpx;
  193. float: right;
  194. margin-top: 20rpx;
  195. }
  196. .charts {
  197. margin-top: 60rpx;
  198. width: 702rpx;
  199. height: 500rpx;
  200. background-color: #FFFFFF;
  201. }
  202. .title1 {
  203. display: flex;
  204. flex-direction: column;
  205. align-items: center;
  206. }
  207. .tiao {
  208. width: 60px;
  209. height: 3px;
  210. margin-top: 20rpx;
  211. background: #007AFF;
  212. }
  213. .param {
  214. font-size: 38rpx;
  215. font-weight: 550;
  216. margin-top: 40rpx;
  217. }
  218. .white {
  219. width: 702rpx;
  220. height: 720rpx;
  221. margin-left: 24rpx;
  222. background-color: white;
  223. margin-top: 28rpx;
  224. border-radius: 10rpx;
  225. }
  226. .white1 {
  227. width: 702rpx;
  228. height: 720rpx;
  229. margin-left: 24rpx;
  230. background-color: white;
  231. margin-top: 28rpx;
  232. border-radius: 10rpx;
  233. }
  234. .chart {
  235. font-size: 26rpx;
  236. height: 300px;
  237. /* background:white; */
  238. background: rgb(30, 130, 250);
  239. display: flex;
  240. flex-direction: row;
  241. align-items: center;
  242. justify-content: center;
  243. }
  244. .charts-box {
  245. margin-left: 8rpx;
  246. margin-right: 8rpx;
  247. }
  248. </style>