line-echarts.vue 3.3 KB

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