bar-echarts.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view class="charts-box">
  3. <qiun-data-charts type="column" :eopts="opts" :chartData="chartData" :ontouch="true" :onzoom="true"
  4. :echartsH5="true" />
  5. </view>
  6. </template>
  7. <script>
  8. import {
  9. nowDate,
  10. timeToDate
  11. } from '../../utils/date.js'
  12. export default {
  13. props: {
  14. echartsData: Object
  15. },
  16. data() {
  17. return {
  18. chartData: {},
  19. //您可以通过修改 config-ucharts.js 文件中下标为 ['column'] 的节点来配置全局默认参数,如都是默认参数,此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式,达到页面简洁的需求。
  20. opts: {
  21. color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
  22. "#ea7ccc"
  23. ],
  24. padding: [15, 15, 0, 5],
  25. enableScroll: true,
  26. legend: {
  27. type: 'scroll',
  28. pageIconSize: 18,
  29. margin: 20,
  30. itemGap: 20,
  31. lineHeight: 20,
  32. top: 0
  33. },
  34. grid: {
  35. bottom: '25%',
  36. top: "50px",
  37. left: "45px",
  38. right: "30px"
  39. },
  40. xAxis: {
  41. disableGrid: true,
  42. scrollShow: false,
  43. itemCount: 2,
  44. scrollAlign: 'right'
  45. // rotateLabel: true,
  46. // rotateAngle: -20
  47. },
  48. yAxis: {
  49. data: [{
  50. min: 0
  51. }]
  52. },
  53. extra: {
  54. column: {
  55. type: "group",
  56. width: 30,
  57. activeBgColor: "#000000",
  58. activeBgOpacity: 0.08,
  59. seriesGap: 10
  60. }
  61. },
  62. tooltip: {
  63. trigger: 'axis',
  64. // axisPointer: {
  65. // type: 'cross',
  66. // label: {
  67. // backgroundColor: '#6a7985'
  68. // }
  69. // }
  70. },
  71. dataZoom: [{
  72. type: 'slider',
  73. show: true,
  74. xAxisIndex: [0],
  75. start: 90,
  76. end: 100
  77. },
  78. {
  79. type: 'slider',
  80. show: true,
  81. yAxisIndex: [0],
  82. left: '93%',
  83. start: 60,
  84. end: 100
  85. },
  86. {
  87. type: 'inside',
  88. xAxisIndex: [0],
  89. start: 90,
  90. end: 100
  91. },
  92. {
  93. type: 'inside',
  94. yAxisIndex: [0],
  95. start: 60,
  96. end: 100
  97. }
  98. ],
  99. },
  100. timeNum: 10,
  101. barTime: null
  102. };
  103. },
  104. mounted() {
  105. this.getEmit();
  106. },
  107. beforeDestroy(){
  108. clearInterval(this.barTime)
  109. this.barTime = null
  110. },
  111. methods: {
  112. getServerData() {
  113. const chartData = this.echartsData.chartItemList
  114. const timeData = chartData[0].valueTimeList
  115. const time = timeData.map(item => {
  116. return item.substring(0, 19)
  117. })
  118. const series = chartData.map(item => {
  119. return {
  120. name: item.describe ? item.describe : item.itemName,
  121. data: item.valueList
  122. }
  123. })
  124. this.opts.xAxis.data = time
  125. let res = {
  126. categories: time,
  127. series: series
  128. };
  129. this.chartData = JSON.parse(JSON.stringify(res));
  130. },
  131. getEmit() {
  132. const {
  133. bucketType,
  134. bucketValue
  135. } = this.echartsData
  136. let time = null
  137. switch (bucketType) {
  138. case 0:
  139. time = 86400000 * bucketValue
  140. this.timeNum = 4
  141. break;
  142. case 1:
  143. time = 3600000 * bucketValue
  144. this.timeNum = 13
  145. break;
  146. case 2:
  147. time = 60000 * bucketValue
  148. this.timeNum = 16
  149. break;
  150. case 3:
  151. time = 1000 * bucketValue
  152. this.timeNum = 19
  153. break;
  154. }
  155. this.getServerData()
  156. this.barTime = setInterval(() => {
  157. let chartParams = {
  158. id: this.echartsData.id,
  159. startTime: timeToDate(new Date().getTime() - 3600000),
  160. endTime: nowDate()
  161. }
  162. uni.$http.get('/chart/getChartById', chartParams).then(res => {
  163. })
  164. }, time)
  165. }
  166. }
  167. };
  168. </script>
  169. <style scoped>
  170. /* 请根据实际需求修改父元素尺寸,组件自动识别宽高 */
  171. .charts-box {
  172. width: 100%;
  173. height: 600rpx;
  174. }
  175. </style>