bar-echarts.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. tooltip: {
  54. trigger: 'axis',
  55. position:'inside'
  56. // axisPointer: {
  57. // type: 'cross',
  58. // label: {
  59. // backgroundColor: '#6a7985'
  60. // }
  61. // }
  62. },
  63. dataZoom: [{
  64. type: 'slider',
  65. show: true,
  66. xAxisIndex: [0],
  67. start: 90,
  68. end: 100
  69. },
  70. {
  71. type: 'slider',
  72. show: true,
  73. yAxisIndex: [0],
  74. left: '93%',
  75. start: 60,
  76. end: 100
  77. },
  78. {
  79. type: 'inside',
  80. xAxisIndex: [0],
  81. start: 90,
  82. end: 100
  83. },
  84. {
  85. type: 'inside',
  86. yAxisIndex: [0],
  87. start: 60,
  88. end: 100
  89. }
  90. ],
  91. },
  92. timeNum: 10,
  93. barTime: null
  94. };
  95. },
  96. mounted() {
  97. this.getEmit();
  98. },
  99. beforeDestroy() {
  100. clearInterval(this.barTime)
  101. this.barTime = null
  102. },
  103. methods: {
  104. getServerData() {
  105. const chartData = this.echartsData.chartItemList
  106. const timeData = chartData[0].valueTimeList
  107. const time = timeData.map(item => {
  108. return item.substring(0, 19)
  109. })
  110. const series = chartData.map(item => {
  111. return {
  112. name: item.describe ? item.describe : item.itemName,
  113. data: item.valueList,
  114. label:{
  115. show:false
  116. }
  117. }
  118. })
  119. this.opts.xAxis.data = time
  120. let res = {
  121. categories: time,
  122. series: series
  123. };
  124. this.chartData = JSON.parse(JSON.stringify(res));
  125. },
  126. getEmit() {
  127. const {
  128. bucketType,
  129. bucketValue
  130. } = this.echartsData
  131. let time = null
  132. switch (bucketType) {
  133. case 0:
  134. time = 86400000 * bucketValue
  135. this.timeNum = 4
  136. break;
  137. case 1:
  138. time = 3600000 * bucketValue
  139. this.timeNum = 13
  140. break;
  141. case 2:
  142. time = 60000 * bucketValue
  143. this.timeNum = 16
  144. break;
  145. case 3:
  146. time = 1000 * bucketValue
  147. this.timeNum = 19
  148. break;
  149. }
  150. this.getServerData()
  151. this.barTime = setInterval(() => {
  152. let chartParams = {
  153. id: this.echartsData.id,
  154. startTime: timeToDate(new Date().getTime() - 3600000),
  155. endTime: nowDate()
  156. }
  157. uni.$http.get('/chart/getChartById', chartParams).then(res => {
  158. const data = res.data
  159. if (data.code === 200) {
  160. let chartItemList = data.chartItemList;
  161. chartItemList.forEach((item, index) => {
  162. if (item.itemId === this.echartsData[
  163. index].itemId) {
  164. if (item.valueList.length !== 0) {
  165. //执行将新数据添加进去,旧数据去除一个
  166. this.echartsData[index].valueList =
  167. this.echartsData[index].valueList
  168. .concat(item.valueList)
  169. this.echartsData[
  170. index]
  171. .valueList.splice(0, item
  172. .valueList.length)
  173. this.echartsData[index]
  174. .valueTimeList = this.echartsData[
  175. index]
  176. .valueTimeList.concat(item
  177. .valueTimeList)
  178. this.echartsData[
  179. index]
  180. .valueTimeList.splice(0,
  181. item
  182. .valueTimeList.length)
  183. }
  184. }
  185. })
  186. this.getServerData()
  187. }
  188. })
  189. }, time)
  190. }
  191. }
  192. };
  193. </script>
  194. <style scoped>
  195. /* 请根据实际需求修改父元素尺寸,组件自动识别宽高 */
  196. .charts-box {
  197. width: 100%;
  198. height: 540rpx;
  199. }
  200. </style>