myCharts.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /**
  2. * 各种画echarts图表的方法都封装在这里
  3. * 注意:这里echarts没有采用按需引入的方式,只是为了方便学习
  4. */
  5. import echarts from 'echarts'
  6. const install = function (Vue) {
  7. Object.defineProperties(Vue.prototype, {
  8. $chart: {
  9. get () {
  10. return {
  11. // 统计分析
  12. line1: function (id, header, data) {
  13. this.chart = echarts.init(document.getElementById(id))
  14. this.chart.clear()
  15. const optionData = {
  16. xAxis: {
  17. type: 'category',
  18. data: header
  19. },
  20. yAxis: {
  21. type: 'value'
  22. },
  23. series: [{
  24. data: data,
  25. type: 'line',
  26. smooth: true
  27. }]
  28. }
  29. this.chart.setOption(optionData)
  30. },
  31. // 访问人数
  32. pie: function (id, data) {
  33. this.chart = echarts.init(document.getElementById(id))
  34. this.chart.clear()
  35. var fontColor = '#000'
  36. const optionData = {
  37. tooltip: {
  38. trigger: 'item',
  39. formatter: '{b}: {c} ({d}%)'
  40. },
  41. legend: {
  42. orient: 'vertical',
  43. x: 'left',
  44. y: '15',
  45. textStyle: {
  46. color: fontColor
  47. },
  48. data: data.header
  49. },
  50. series: [
  51. {
  52. type: 'pie',
  53. radius: ['55%', '70%'],
  54. center: data.center || ['70%', '60%'],
  55. color: data.color || ['#67c241', '#e6a139', '#f76b6c'],
  56. avoidLabelOverlap: false,
  57. label: {
  58. normal: {
  59. show: false,
  60. position: 'center'
  61. },
  62. emphasis: {
  63. show: true,
  64. textStyle: {
  65. fontSize: '20',
  66. fontWeight: 'bold',
  67. color: '#000'
  68. }
  69. }
  70. },
  71. labelLine: {
  72. normal: {
  73. show: false
  74. }
  75. },
  76. data: data.data
  77. }
  78. ]
  79. }
  80. this.chart.setOption(optionData, true)
  81. },
  82. // 文物趋势
  83. line2: function (id, header, data) {
  84. this.chart = echarts.init(document.getElementById(id))
  85. this.chart.clear()
  86. var fontColor = '#000'
  87. var borderColor = 'rgba(0,0,0,0.1)'
  88. const optionData = {
  89. grid: {
  90. left: '5%',
  91. right: '8%',
  92. top: '18%',
  93. bottom: '5%',
  94. containLabel: true
  95. },
  96. tooltip: {
  97. show: true,
  98. trigger: 'item'
  99. },
  100. legend: {
  101. show: true,
  102. x: '200',
  103. y: '22',
  104. icon: 'stack',
  105. itemWidth: 10,
  106. itemHeight: 10,
  107. textStyle: {
  108. color: fontColor
  109. },
  110. data: ['全部', '青铜', '瓷器', '陶器']
  111. },
  112. xAxis: [{
  113. type: 'category',
  114. boundaryGap: false,
  115. axisLabel: {
  116. color: fontColor
  117. },
  118. axisLine: {
  119. show: true,
  120. lineStyle: {
  121. color: borderColor
  122. }
  123. },
  124. axisTick: {
  125. show: false
  126. },
  127. splitLine: {
  128. show: true,
  129. lineStyle: {
  130. color: borderColor
  131. }
  132. },
  133. data: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
  134. }],
  135. yAxis: [{
  136. type: 'value',
  137. axisLabel: {
  138. formatter: '{value}',
  139. textStyle: {
  140. color: fontColor
  141. }
  142. },
  143. axisLine: {
  144. lineStyle: {
  145. color: borderColor
  146. }
  147. },
  148. axisTick: {
  149. show: false
  150. },
  151. splitLine: {
  152. show: true,
  153. lineStyle: {
  154. color: borderColor
  155. }
  156. }
  157. }],
  158. series: [
  159. {
  160. name: '青铜',
  161. type: 'line',
  162. stack: '总量',
  163. symbol: 'rect',
  164. symbolSize: 9,
  165. itemStyle: {
  166. normal: {
  167. color: '#67c241',
  168. lineStyle: {
  169. color: '#67c241',
  170. width: 1
  171. }
  172. }
  173. },
  174. data: [220, 182, 191, 234, 290, 330, 310, 201, 154, 190, 330, 410]
  175. },
  176. {
  177. name: '瓷器',
  178. type: 'line',
  179. stack: '总量',
  180. symbol: 'rect',
  181. symbolSize: 9,
  182. itemStyle: {
  183. normal: {
  184. color: '#e6a139',
  185. lineStyle: {
  186. color: '#e6a139',
  187. width: 1
  188. }
  189. }
  190. },
  191. data: [150, 22, 201, 154, 190, 330, 410, 150, 232, 201, 154, 190]
  192. },
  193. {
  194. name: '陶器',
  195. type: 'line',
  196. stack: '总量',
  197. symbol: 'rect',
  198. symbolSize: 9,
  199. itemStyle: {
  200. normal: {
  201. color: '#f76b6c',
  202. lineStyle: {
  203. color: '#f76b6c',
  204. width: 1
  205. }
  206. }
  207. },
  208. data: [0, 182, 191, 234, 0, 330, 10, 201, 154, 190, 330, 410]
  209. },
  210. {
  211. name: '全部',
  212. type: 'line',
  213. stack: '总量',
  214. symbol: 'rect',
  215. symbolSize: 9,
  216. itemStyle: {
  217. normal: {
  218. color: '#000',
  219. lineStyle: {
  220. color: '#000',
  221. width: 1
  222. }
  223. }
  224. },
  225. markPoint: {
  226. itemStyle: {
  227. normal: {
  228. color: 'red'
  229. }
  230. }
  231. },
  232. data: [120, 120, 301, 134, 390, 630, 810, 120, 491, 120, 290, 330]
  233. }
  234. ]
  235. }
  236. this.chart.setOption(optionData)
  237. }
  238. }
  239. }
  240. }
  241. })
  242. }
  243. export default {
  244. install
  245. }