planImplementationJS.js 5.2 KB

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