mixChart.vue 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <div :class="className" :id="id" :style="{height:height,width:width}"></div>
  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. borderWidth: 0,
  77. top: 110,
  78. bottom: 95,
  79. textStyle: {
  80. color: '#fff'
  81. }
  82. },
  83. legend: {
  84. x: '5%',
  85. top: '10%',
  86. textStyle: {
  87. color: '#90979c'
  88. },
  89. data: ['female', 'male', 'average']
  90. },
  91. calculable: true,
  92. xAxis: [{
  93. type: 'category',
  94. axisLine: {
  95. lineStyle: {
  96. color: '#90979c'
  97. }
  98. },
  99. splitLine: {
  100. show: false
  101. },
  102. axisTick: {
  103. show: false
  104. },
  105. splitArea: {
  106. show: false
  107. },
  108. axisLabel: {
  109. interval: 0
  110. },
  111. data: xData
  112. }],
  113. yAxis: [{
  114. type: 'value',
  115. splitLine: {
  116. show: false
  117. },
  118. axisLine: {
  119. lineStyle: {
  120. color: '#90979c'
  121. }
  122. },
  123. axisTick: {
  124. show: false
  125. },
  126. axisLabel: {
  127. interval: 0
  128. },
  129. splitArea: {
  130. show: false
  131. }
  132. }],
  133. dataZoom: [{
  134. show: true,
  135. height: 30,
  136. xAxisIndex: [
  137. 0
  138. ],
  139. bottom: 30,
  140. start: 10,
  141. end: 80,
  142. 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',
  143. handleSize: '110%',
  144. handleStyle: {
  145. color: '#d3dee5'
  146. },
  147. textStyle: {
  148. color: '#fff' },
  149. borderColor: '#90979c'
  150. }, {
  151. type: 'inside',
  152. show: true,
  153. height: 15,
  154. start: 1,
  155. end: 35
  156. }],
  157. series: [{
  158. name: 'female',
  159. type: 'bar',
  160. stack: 'total',
  161. barMaxWidth: 35,
  162. barGap: '10%',
  163. itemStyle: {
  164. normal: {
  165. color: 'rgba(255,144,128,1)',
  166. label: {
  167. show: true,
  168. textStyle: {
  169. color: '#fff'
  170. },
  171. position: 'insideTop',
  172. formatter(p) {
  173. return p.value > 0 ? p.value : ''
  174. }
  175. }
  176. }
  177. },
  178. data: [
  179. 709,
  180. 1917,
  181. 2455,
  182. 2610,
  183. 1719,
  184. 1433,
  185. 1544,
  186. 3285,
  187. 5208,
  188. 3372,
  189. 2484,
  190. 4078
  191. ]
  192. },
  193. {
  194. name: 'male',
  195. type: 'bar',
  196. stack: 'total',
  197. itemStyle: {
  198. normal: {
  199. color: 'rgba(0,191,183,1)',
  200. barBorderRadius: 0,
  201. label: {
  202. show: true,
  203. position: 'top',
  204. formatter(p) {
  205. return p.value > 0 ? p.value : ''
  206. }
  207. }
  208. }
  209. },
  210. data: [
  211. 327,
  212. 1776,
  213. 507,
  214. 1200,
  215. 800,
  216. 482,
  217. 204,
  218. 1390,
  219. 1001,
  220. 951,
  221. 381,
  222. 220
  223. ]
  224. }, {
  225. name: 'average',
  226. type: 'line',
  227. stack: 'total',
  228. symbolSize: 10,
  229. symbol: 'circle',
  230. itemStyle: {
  231. normal: {
  232. color: 'rgba(252,230,48,1)',
  233. barBorderRadius: 0,
  234. label: {
  235. show: true,
  236. position: 'top',
  237. formatter(p) {
  238. return p.value > 0 ? p.value : ''
  239. }
  240. }
  241. }
  242. },
  243. data: [
  244. 1036,
  245. 3693,
  246. 2962,
  247. 3810,
  248. 2519,
  249. 1915,
  250. 1748,
  251. 4675,
  252. 6209,
  253. 4323,
  254. 2865,
  255. 4298
  256. ]
  257. }
  258. ]
  259. })
  260. }
  261. }
  262. }
  263. </script>