planImplementationJS.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import echarts from 'echarts'
  2. export default {
  3. data () {
  4. return {
  5. barLable: {
  6. show: true,
  7. position: 'top',
  8. textStyle: { // 数值样式
  9. color: 'black',
  10. fontSize: 12
  11. },
  12. formatter: (params) => {
  13. // 这个回调函数不起作用了
  14. return params.value === '0' ? '' : params.value
  15. }
  16. }
  17. }
  18. },
  19. methods: {
  20. getOption (totalMs = 0) {
  21. console.log(totalMs)
  22. const option = {
  23. series: [
  24. {
  25. type: 'gauge',
  26. min: 0,
  27. max: 100,
  28. animationDuration: 3000,
  29. axisLine: {
  30. lineStyle: {
  31. width: 30,
  32. color: [
  33. [0.3, '#fd666d'],
  34. [0.7, '#37a2da'],
  35. [1, '#67e0e3']
  36. ]
  37. }
  38. },
  39. pointer: {
  40. itemStyle: {
  41. color: 'auto'
  42. }
  43. },
  44. axisTick: {
  45. distance: -30,
  46. length: 8,
  47. lineStyle: {
  48. color: '#fff',
  49. width: 2
  50. }
  51. },
  52. splitLine: {
  53. distance: -30,
  54. length: 30,
  55. lineStyle: {
  56. color: '#fff',
  57. width: 4
  58. }
  59. },
  60. axisLabel: {
  61. show: true
  62. },
  63. detail: {
  64. valueAnimation: true,
  65. formatter: '{value} %',
  66. color: 'auto',
  67. top: '100%',
  68. offsetCenter: [0, '75%']
  69. },
  70. data: [{ value: totalMs, top: '100%' }]
  71. }
  72. ]
  73. }
  74. const accept = echarts.init(this.$refs.chart1)
  75. accept.setOption(JSON.parse(JSON.stringify(option)))
  76. // this.show1 = true
  77. },
  78. barDataPlan (data) {
  79. data.series.forEach(item => {
  80. item.label = this.barLable
  81. item.type = 'bar'
  82. item.barGap = 0
  83. item.emphasis = {
  84. focus: 'series'
  85. }
  86. })
  87. const barDataTy = {
  88. // 图例设置
  89. legend: {
  90. textStyle: {
  91. fontSize: 12,
  92. color: '#333'
  93. }
  94. },
  95. title: {
  96. show: true,
  97. text: data.title,
  98. textStyle: {
  99. // color: '#fff',
  100. fontSize: 20,
  101. fontWeight: '600'
  102. },
  103. textAlign: 'center',
  104. left: '50%',
  105. top: '20px'
  106. },
  107. xAxis: {
  108. name: '部门',
  109. type: 'category',
  110. data: data.xAxisData,
  111. axisTick: {
  112. alignWithLabel: true
  113. },
  114. axisLabel: {
  115. rotate: 30,
  116. interval: 0,
  117. margin: 10
  118. }
  119. },
  120. yAxis: {
  121. type: 'value',
  122. name: '数量(个)',
  123. minInterval: 1,
  124. nameTextStyle: {
  125. fontSize: 14
  126. },
  127. splitLine: {
  128. show: false
  129. }
  130. },
  131. series: data.series,
  132. color: data.color,
  133. tooltip: {
  134. show: true,
  135. trigger: 'axis'
  136. }
  137. }
  138. const accept = echarts.init(this.$refs.chart2)
  139. accept.setOption(JSON.parse(JSON.stringify(barDataTy)))
  140. }
  141. }
  142. }