chart.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <div>
  3. <Echart
  4. :options="options"
  5. id="bottom3Chart"
  6. height="310px"
  7. width="450px"
  8. ></Echart>
  9. </div>
  10. </template>
  11. <script>
  12. import Echart from '@/common/echart'
  13. export default {
  14. data() {
  15. return {
  16. options: {},
  17. // 定义颜色
  18. colorList: {
  19. linearYtoG: {
  20. type: 'linear',
  21. x: 0,
  22. y: 0,
  23. x2: 1,
  24. y2: 1,
  25. colorStops: [
  26. {
  27. offset: 0,
  28. color: '#f5b44d'
  29. },
  30. {
  31. offset: 1,
  32. color: '#28f8de'
  33. }
  34. ]
  35. },
  36. linearGtoB: {
  37. type: 'linear',
  38. x: 0,
  39. y: 0,
  40. x2: 1,
  41. y2: 0,
  42. colorStops: [
  43. {
  44. offset: 0,
  45. color: '#43dfa2'
  46. },
  47. {
  48. offset: 1,
  49. color: '#28f8de'
  50. }
  51. ]
  52. },
  53. linearBtoG: {
  54. type: 'linear',
  55. x: 0,
  56. y: 0,
  57. x2: 1,
  58. y2: 0,
  59. colorStops: [
  60. {
  61. offset: 0,
  62. color: '#1c98e8'
  63. },
  64. {
  65. offset: 1,
  66. color: '#28f8de'
  67. }
  68. ]
  69. },
  70. areaBtoG: {
  71. type: 'linear',
  72. x: 0,
  73. y: 0,
  74. x2: 0,
  75. y2: 1,
  76. colorStops: [
  77. {
  78. offset: 0,
  79. color: 'rgba(35,184,210,.2)'
  80. },
  81. {
  82. offset: 1,
  83. color: 'rgba(35,184,210,0)'
  84. }
  85. ]
  86. }
  87. }
  88. }
  89. },
  90. components: {
  91. Echart
  92. },
  93. props: {
  94. cdata: {
  95. type: Object,
  96. default: () => ({})
  97. }
  98. },
  99. watch: {
  100. cdata: {
  101. handler(newData) {
  102. this.options = {
  103. grid: {
  104. left: '10%',
  105. bottom: 25,
  106. },
  107. xAxis: {
  108. type: 'category',
  109. position: 'bottom',
  110. axisLabel: {
  111. fontSize: 15
  112. },
  113. data: newData.weekCategory
  114. },
  115. // 下方Y轴
  116. yAxis: {
  117. name: '',
  118. nameLocation: 'end',
  119. nameGap: 24,
  120. nameTextStyle: {
  121. color: 'rgba(255,255,255,.5)',
  122. fontSize: 14
  123. },
  124. max:newData.maxData,
  125. splitNumber: 4,
  126. min: 90,
  127. //min:newData.minData,
  128. splitLine: {
  129. show: true,
  130. lineStyle: {
  131. color: '#fff',
  132. opacity: 0.1
  133. }
  134. },
  135. axisLabel: {
  136. //color: 'rgba(255,255,255,.8)',
  137. fontSize: 15,
  138. formatter: '{value}%',
  139. }
  140. },
  141. series: [
  142. {
  143. name: '',
  144. type: 'line',
  145. smooth: true,
  146. symbol: 'emptyCircle',
  147. symbolSize: 8,
  148. itemStyle: {
  149. normal: {
  150. color: '#fff'
  151. }
  152. },
  153. lineStyle: {
  154. normal: {
  155. color: this.colorList.linearBtoG,
  156. width: 4
  157. }
  158. },
  159. areaStyle: {
  160. normal: {
  161. color: this.colorList.areaBtoG
  162. }
  163. },
  164. data: newData.weekLineData,
  165. label: {
  166. show: true,
  167. position: 'top',
  168. fontSize:14,
  169. color:'#fff'
  170. },
  171. lineSmooth: true,
  172. markLine: {
  173. silent: true,
  174. data: [
  175. {yAxis: newData.goalData}
  176. ],
  177. // precision: 0,
  178. label: {
  179. normal: {
  180. formatter: '目标线: \n {c}',
  181. color:'#fff'
  182. },
  183. },
  184. lineStyle: {
  185. normal: {
  186. fontSize: 16,
  187. color: 'rgba(248,211,81,.7)'
  188. }
  189. }
  190. },
  191. tooltip: {
  192. position: 'top',
  193. formatter: '{c} %',
  194. backgroundColor: 'rgba(28,152,232,.2)',
  195. padding: 6
  196. }
  197. },
  198. {
  199. name: '占位背景',
  200. type: 'bar',
  201. itemStyle: {
  202. normal: {
  203. show: true,
  204. color: '#000',
  205. opacity: 0
  206. }
  207. },
  208. silent: true,
  209. barWidth: '50%',
  210. data: newData.weekMaxData,
  211. animation: false
  212. }
  213. ]
  214. }
  215. },
  216. immediate: true,
  217. deep: true
  218. }
  219. }
  220. }
  221. </script>