chart.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div>
  3. <charts id="chart" height="255px" :option="option"/>
  4. </div>
  5. </template>
  6. <script>
  7. import charts from '../../../components/echarts/index.vue'
  8. export default {
  9. components: {charts},
  10. props: {
  11. deptId: {
  12. type: String,
  13. default: ''
  14. },
  15. quarter: {
  16. type: Object,
  17. default: null
  18. },
  19. year: {
  20. type: String,
  21. default: null
  22. }
  23. },
  24. watch: {
  25. deptId: {
  26. handler(val) {
  27. this.init()
  28. },
  29. immediate: true
  30. },
  31. quarter: {
  32. handler(val) {
  33. this.init()
  34. },
  35. immediate: true
  36. },
  37. year: {
  38. handler(val) {
  39. this.init()
  40. },
  41. immediate: true
  42. }
  43. },
  44. data() {
  45. return {
  46. option: {
  47. title: {
  48. text: '单位:(万元)',
  49. textStyle: {
  50. color: 'white',
  51. fontSize: '12'
  52. },
  53. x: 'right',
  54. y: 'top'
  55. },
  56. xAxis: [
  57. {
  58. type: 'category',
  59. axisTick: {show: false},
  60. splitLine: {show: false},
  61. data: [],
  62. axisPointer: {
  63. type: 'shadow'
  64. },
  65. axisLine: {
  66. show: true,
  67. lineStyle: {
  68. color: '#B2BFCB',
  69. width: '2'
  70. }
  71. }
  72. }
  73. ],
  74. yAxis: [
  75. {
  76. type: 'value',
  77. axisTick: {show: false},
  78. splitLine: {show: false},
  79. axisLine: {
  80. show: true,
  81. lineStyle: {
  82. color: '#B2BFCB',
  83. width: '2'
  84. }
  85. }
  86. },
  87. {
  88. type: 'value',
  89. name: '',
  90. axisTick: {show: true},
  91. splitLine: {show: true},
  92. interval: 5,
  93. axisLabel: {
  94. formatter: '',
  95. lineStyle: {
  96. color: 'red',
  97. width: '2'
  98. }
  99. }
  100. }
  101. ],
  102. series: [
  103. {
  104. name: '计划完成总投资',
  105. type: 'line',
  106. barWidth: '45',
  107. tooltip: {
  108. valueFormatter: function (value) {
  109. return value + ' ml'
  110. }
  111. },
  112. itemStyle: {
  113. normal: {
  114. label: {
  115. show: true,
  116. color: 'red',
  117. fontSize: 12
  118. }
  119. }
  120. },
  121. label: {
  122. show: true,
  123. position: 'top'
  124. },
  125. lineStyle: {color: '#528BEC', type: 'solid', borderColor: 'red'},
  126. data: []
  127. },
  128. {
  129. name: '平均值',
  130. type: 'line',
  131. barWidth: '45',
  132. tooltip: {
  133. valueFormatter: function (value) {
  134. return value + ' ml'
  135. }
  136. },
  137. itemStyle: {
  138. normal: {
  139. label: {
  140. show: true,
  141. color: 'red',
  142. fontSize: 12
  143. }
  144. }
  145. },
  146. label: {
  147. show: true,
  148. position: 'top'
  149. },
  150. lineStyle: {color: 'red', type: 'solid', borderColor: 'red'},
  151. data: []
  152. }
  153. ]
  154. },
  155. type: 1
  156. }
  157. },
  158. created() {
  159. },
  160. methods: {
  161. init() {
  162. this.$api.invest.count({
  163. deptId: this.deptId === null ? '' : this.deptId,
  164. year: this.year === null ? '' : this.year,
  165. quarter: this.quarter.value === undefined ? '' : this.quarter.value
  166. }).then(res => {
  167. if (res.code === 200) {
  168. this.option.xAxis[0].data = res.data.map(res => res.month)
  169. this.option.series[0].data = res.data.map(res => res.sum_complete_amount)
  170. this.option.series[1].data = res.data.map(res => res.average)
  171. }
  172. })
  173. }
  174. }
  175. }
  176. </script>
  177. <style scoped lang="scss" type="text/scss"></style>