LineChart.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <div :class="className" :style="{height:height,width:width}" />
  3. </template>
  4. <script>
  5. import echarts from 'echarts'
  6. require('echarts/theme/macarons') // echarts theme
  7. import resize from './mixins/resize'
  8. export default {
  9. mixins: [resize],
  10. props: {
  11. className: {
  12. type: String,
  13. default: 'chart'
  14. },
  15. width: {
  16. type: String,
  17. default: '100%'
  18. },
  19. height: {
  20. type: String,
  21. default: '350px'
  22. },
  23. autoResize: {
  24. type: Boolean,
  25. default: true
  26. },
  27. chartData: {
  28. type: Object,
  29. required: true
  30. }
  31. },
  32. data() {
  33. return {
  34. chart: null
  35. }
  36. },
  37. watch: {
  38. chartData: {
  39. deep: true,
  40. handler(val) {
  41. this.setOptions(val)
  42. }
  43. }
  44. },
  45. mounted() {
  46. this.$nextTick(() => {
  47. this.initChart()
  48. })
  49. },
  50. beforeDestroy() {
  51. if (!this.chart) {
  52. return
  53. }
  54. this.chart.dispose()
  55. this.chart = null
  56. },
  57. methods: {
  58. initChart() {
  59. this.chart = echarts.init(this.$el, 'macarons')
  60. this.setOptions(this.chartData)
  61. },
  62. setOptions({ czjs, czxz,hjjs,hjxz,time } = {}) {
  63. // console.log(x,y[0].data,45)
  64. this.chart.setOption({
  65. xAxis: {
  66. data: time,
  67. boundaryGap: false,
  68. axisTick: {
  69. show: false
  70. }
  71. },
  72. grid: {
  73. left: 10,
  74. right: 10,
  75. bottom: 20,
  76. top: 30,
  77. containLabel: true
  78. },
  79. tooltip: {
  80. trigger: 'axis',
  81. axisPointer: {
  82. type: 'cross'
  83. },
  84. padding: [5, 10]
  85. },
  86. yAxis: {
  87. axisTick: {
  88. show: false
  89. }
  90. },
  91. legend: {
  92. data: ''
  93. },
  94. series: [{
  95. name: '五保户', itemStyle: {
  96. normal: {
  97. color: '#FF005A',
  98. lineStyle: {
  99. color: '#FF005A',
  100. width: 2
  101. }
  102. }
  103. },
  104. smooth: true,
  105. type: 'line',
  106. data: czjs,
  107. animationDuration: 2800,
  108. animationEasing: 'cubicInOut'
  109. },
  110. {
  111. name: '低保户',
  112. smooth: true,
  113. type: 'line',
  114. itemStyle: {
  115. normal: {
  116. color: '#3888fa',
  117. lineStyle: {
  118. color: '#3888fa',
  119. width: 2
  120. },
  121. areaStyle: {
  122. color: '#f3f8ff'
  123. }
  124. }
  125. },
  126. data:czxz,
  127. animationDuration: 2800,
  128. animationEasing: 'quadraticOut'
  129. },
  130. {
  131. name: '贫困户',
  132. smooth: true,
  133. type: 'line',
  134. itemStyle: {
  135. normal: {
  136. color: '#47d737',
  137. lineStyle: {
  138. color: '#47d737',
  139. width: 2
  140. },
  141. areaStyle: {
  142. color: '#f3f8ff'
  143. }
  144. }
  145. },
  146. data:hjxz,
  147. animationDuration: 2800,
  148. animationEasing: 'quadraticOut'
  149. },
  150. {
  151. name: '党员',
  152. smooth: true,
  153. type: 'line',
  154. itemStyle: {
  155. normal: {
  156. color: '#fe4809',
  157. lineStyle: {
  158. color: '#fe4809',
  159. width: 2
  160. },
  161. areaStyle: {
  162. color: '#f3f8ff'
  163. }
  164. }
  165. },
  166. data:hjjs,
  167. animationDuration: 2800,
  168. animationEasing: 'quadraticOut'
  169. },
  170. {
  171. name: '退伍军人',
  172. smooth: true,
  173. type: 'line',
  174. itemStyle: {
  175. normal: {
  176. color: '#fe4809',
  177. lineStyle: {
  178. color: '#fe4809',
  179. width: 2
  180. },
  181. areaStyle: {
  182. color: '#f3f8ff'
  183. }
  184. }
  185. },
  186. data:hjjs,
  187. animationDuration: 2800,
  188. animationEasing: 'quadraticOut'
  189. },
  190. ]
  191. })
  192. }
  193. }
  194. }
  195. </script>