MixChart.vue 5.5 KB

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