planImplementationJS.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import * as 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. center: ['50%', '65%'],
  36. axisLine: {
  37. lineStyle: {
  38. width: 30,
  39. color: [
  40. [0.3, '#fd666d'],
  41. [0.7, '#37a2da'],
  42. [1, '#67e0e3']
  43. ]
  44. }
  45. },
  46. pointer: {
  47. itemStyle: {
  48. color: 'auto'
  49. }
  50. },
  51. axisTick: {
  52. distance: -30,
  53. length: 8,
  54. lineStyle: {
  55. color: '#fff',
  56. width: 2
  57. }
  58. },
  59. splitLine: {
  60. distance: -30,
  61. length: 30,
  62. lineStyle: {
  63. color: '#fff',
  64. width: 4
  65. }
  66. },
  67. axisLabel: {
  68. show: true
  69. },
  70. detail: {
  71. valueAnimation: true,
  72. formatter: '{value} %',
  73. color: 'auto',
  74. top: '100%',
  75. offsetCenter: [0, '65%']
  76. },
  77. title: {
  78. offsetCenter: [0, '-120%'],
  79. fontWeight: 'bold',
  80. fontSize: 20
  81. },
  82. data: [{ value: leftData.leftTotal <= 100 ? leftData.leftTotal : 100, name: leftData.title || '', top: '100%' }]
  83. }
  84. ]
  85. }
  86. const accept = echarts.init(this.$refs.chart1)
  87. accept.setOption(JSON.parse(JSON.stringify(option)))
  88. // this.show1 = true
  89. },
  90. barDataPlan (data, rightShow, direction) {
  91. let barDataTy = null
  92. if (!rightShow) {
  93. data.series.forEach(item => {
  94. item.label = item.label || this.barLable
  95. item.type = 'bar'
  96. item.barGap = 0
  97. item.emphasis = {
  98. focus: 'series'
  99. }
  100. })
  101. const xAxis = {
  102. type: 'value',
  103. name: data.xAxisName || '数量(个)',
  104. minInterval: 1,
  105. axisTick: {
  106. alignWithLabel: true
  107. }
  108. }
  109. const yAxis = {
  110. type: 'category',
  111. name: data.yAxisName || '部门',
  112. nameTextStyle: {
  113. fontSize: 14
  114. },
  115. splitLine: {
  116. show: false
  117. },
  118. data: data.yAxisData
  119. }
  120. barDataTy = {
  121. // 图例设置
  122. legend: {
  123. textStyle: {
  124. fontSize: 12,
  125. color: '#333'
  126. }
  127. },
  128. title: {
  129. show: true,
  130. text: data.title,
  131. textStyle: {
  132. // color: '#fff',
  133. fontSize: 20,
  134. fontWeight: '600'
  135. },
  136. textAlign: 'center',
  137. left: '50%',
  138. top: '20px'
  139. },
  140. xAxis: direction === 'x' ? yAxis : xAxis,
  141. yAxis: direction === 'x' ? xAxis : yAxis,
  142. series: data.series,
  143. color: data.color,
  144. tooltip: data.tooltip || this.tooltip
  145. }
  146. } else {
  147. barDataTy = data
  148. }
  149. const accept = echarts.init(this.$refs.chart2)
  150. accept.setOption(JSON.parse(JSON.stringify(barDataTy)))
  151. }
  152. }
  153. }