pie-echarts.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view class="charts-box">
  3. <qiun-data-charts type="pie" :eopts="opts" :chartData="chartData" :echartsH5="true" />
  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 文件中下标为 ['ring'] 的节点来配置全局默认参数,如都是默认参数,此处可以不传 opts 。实际应用过程中 opts 只需传入与全局默认参数中不一致的【某一个属性】即可实现同类型的图表显示不同的样式,达到页面简洁的需求。
  19. opts: {
  20. tooltip: {
  21. trigger: 'item'
  22. },
  23. legend: {
  24. type: 'scroll',
  25. orient: 'horizontal',
  26. top: 'bottom'
  27. }
  28. },
  29. timeNum: 10,
  30. pieTime: null
  31. };
  32. },
  33. mounted() {
  34. this.getEmit()
  35. },
  36. beforeDestroy() {
  37. clearInterval(this.pieTime)
  38. this.pieTime = null
  39. },
  40. methods: {
  41. getServerData() {
  42. const chartData = this.echartsData.chartItemList[0]
  43. chartData.valueTimeList = chartData.valueTimeList.map(item => {
  44. return item.substring(0, this.timeNum)
  45. })
  46. const {
  47. valueList,
  48. valueTimeList
  49. } = chartData
  50. let data = valueTimeList.map((item, i) => {
  51. return {
  52. name: item,
  53. value: valueList[i]
  54. }
  55. })
  56. let chartDataPie = {
  57. "series": [{
  58. 'type': 'pie',
  59. radius: '55%',
  60. label: {
  61. show: false
  62. },
  63. data: data,
  64. center: ['50%', '30%']
  65. }]
  66. }
  67. this.chartData = chartDataPie
  68. },
  69. getEmit() {
  70. const {
  71. bucketType,
  72. bucketValue
  73. } = this.echartsData
  74. let time = null
  75. switch (bucketType) {
  76. case 0:
  77. time = 86400000 * bucketValue
  78. this.timeNum = 4
  79. break;
  80. case 1:
  81. time = 3600000 * bucketValue
  82. this.timeNum = 13
  83. break;
  84. case 2:
  85. time = 60000 * bucketValue
  86. this.timeNum = 16
  87. break;
  88. case 3:
  89. time = 1000 * bucketValue
  90. this.timeNum = 19
  91. break;
  92. }
  93. this.getServerData();
  94. this.pieTime = setInterval(() => {
  95. let chartParams = {
  96. id: this.echartsData.id,
  97. startTime: timeToDate(new Date().getTime() - 3600000),
  98. endTime: nowDate()
  99. }
  100. uni.$http.get('/chart/getChartById', chartParams).then(res => {
  101. })
  102. }, time)
  103. }
  104. }
  105. };
  106. </script>
  107. <style scoped>
  108. /* 请根据实际需求修改父元素尺寸,组件自动识别宽高 */
  109. .charts-box {
  110. width: 100%;
  111. height: 600rpx;
  112. }
  113. </style>