line-echarts1.vue 4.2 KB

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