mixChart.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <div :class="className" :id="id" :style="{height:height,width:width}"></div>
  3. </template>
  4. <script>
  5. import echarts from 'echarts'
  6. export default {
  7. props: {
  8. className: {
  9. type: String,
  10. default: 'chart'
  11. },
  12. id: {
  13. type: String,
  14. default: 'chart'
  15. },
  16. width: {
  17. type: String,
  18. default: '200px'
  19. },
  20. height: {
  21. type: String,
  22. default: '200px'
  23. }
  24. },
  25. data() {
  26. return {
  27. chart: null
  28. }
  29. },
  30. mounted() {
  31. this.initChart()
  32. this.chart = null
  33. },
  34. beforeDestroy() {
  35. if (!this.chart) {
  36. return
  37. }
  38. this.chart.dispose()
  39. this.chart = null
  40. },
  41. methods: {
  42. initChart() {
  43. this.chart = echarts.init(document.getElementById(this.id))
  44. const xData = (function() {
  45. const data = []
  46. for (let i = 1; i < 13; i++) {
  47. data.push(i + 'month')
  48. }
  49. return data
  50. }())
  51. this.chart.setOption({
  52. backgroundColor: '#344b58',
  53. title: {
  54. text: 'statistics',
  55. x: '20',
  56. top: '20',
  57. textStyle: {
  58. color: '#fff',
  59. fontSize: '22'
  60. },
  61. subtextStyle: {
  62. color: '#90979c',
  63. fontSize: '16'
  64. }
  65. },
  66. tooltip: {
  67. trigger: 'axis',
  68. axisPointer: {
  69. textStyle: {
  70. color: '#fff'
  71. }
  72. }
  73. },
  74. grid: {
  75. borderWidth: 0,
  76. top: 110,
  77. bottom: 95,
  78. textStyle: {
  79. color: '#fff'
  80. }
  81. },
  82. legend: {
  83. x: '5%',
  84. top: '10%',
  85. textStyle: {
  86. color: '#90979c'
  87. },
  88. data: ['female', 'male', 'average']
  89. },
  90. calculable: true,
  91. xAxis: [{
  92. type: 'category',
  93. axisLine: {
  94. lineStyle: {
  95. color: '#90979c'
  96. }
  97. },
  98. splitLine: {
  99. show: false
  100. },
  101. axisTick: {
  102. show: false
  103. },
  104. splitArea: {
  105. show: false
  106. },
  107. axisLabel: {
  108. interval: 0
  109. },
  110. data: xData
  111. }],
  112. yAxis: [{
  113. type: 'value',
  114. splitLine: {
  115. show: false
  116. },
  117. axisLine: {
  118. lineStyle: {
  119. color: '#90979c'
  120. }
  121. },
  122. axisTick: {
  123. show: false
  124. },
  125. axisLabel: {
  126. interval: 0
  127. },
  128. splitArea: {
  129. show: false
  130. }
  131. }],
  132. dataZoom: [{
  133. show: true,
  134. height: 30,
  135. xAxisIndex: [
  136. 0
  137. ],
  138. bottom: 30,
  139. start: 10,
  140. end: 80,
  141. handleIcon: 'path://M306.1,413c0,2.2-1.8,4-4,4h-59.8c-2.2,0-4-1.8-4-4V200.8c0-2.2,1.8-4,4-4h59.8c2.2,0,4,1.8,4,4V413z',
  142. handleSize: '110%',
  143. handleStyle: {
  144. color: '#d3dee5'
  145. },
  146. textStyle: {
  147. color: '#fff' },
  148. borderColor: '#90979c'
  149. }, {
  150. type: 'inside',
  151. show: true,
  152. height: 15,
  153. start: 1,
  154. end: 35
  155. }],
  156. series: [{
  157. name: 'female',
  158. type: 'bar',
  159. stack: 'total',
  160. barMaxWidth: 35,
  161. barGap: '10%',
  162. itemStyle: {
  163. normal: {
  164. color: 'rgba(255,144,128,1)',
  165. label: {
  166. show: true,
  167. textStyle: {
  168. color: '#fff'
  169. },
  170. position: 'insideTop',
  171. formatter(p) {
  172. return p.value > 0 ? p.value : ''
  173. }
  174. }
  175. }
  176. },
  177. data: [
  178. 709,
  179. 1917,
  180. 2455,
  181. 2610,
  182. 1719,
  183. 1433,
  184. 1544,
  185. 3285,
  186. 5208,
  187. 3372,
  188. 2484,
  189. 4078
  190. ]
  191. },
  192. {
  193. name: 'male',
  194. type: 'bar',
  195. stack: 'total',
  196. itemStyle: {
  197. normal: {
  198. color: 'rgba(0,191,183,1)',
  199. barBorderRadius: 0,
  200. label: {
  201. show: true,
  202. position: 'top',
  203. formatter(p) {
  204. return p.value > 0 ? p.value : ''
  205. }
  206. }
  207. }
  208. },
  209. data: [
  210. 327,
  211. 1776,
  212. 507,
  213. 1200,
  214. 800,
  215. 482,
  216. 204,
  217. 1390,
  218. 1001,
  219. 951,
  220. 381,
  221. 220
  222. ]
  223. }, {
  224. name: 'average',
  225. type: 'line',
  226. stack: 'total',
  227. symbolSize: 10,
  228. symbol: 'circle',
  229. itemStyle: {
  230. normal: {
  231. color: 'rgba(252,230,48,1)',
  232. barBorderRadius: 0,
  233. label: {
  234. show: true,
  235. position: 'top',
  236. formatter(p) {
  237. return p.value > 0 ? p.value : ''
  238. }
  239. }
  240. }
  241. },
  242. data: [
  243. 1036,
  244. 3693,
  245. 2962,
  246. 3810,
  247. 2519,
  248. 1915,
  249. 1748,
  250. 4675,
  251. 6209,
  252. 4323,
  253. 2865,
  254. 4298
  255. ]
  256. }
  257. ]
  258. })
  259. }
  260. }
  261. }
  262. </script>