BaseGeniusLine.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <div>
  3. <Loading :top="100" v-show="dataLoading" type="1"></Loading>
  4. <div :id='echartsId' class='myLine'></div>
  5. </div>
  6. </template>
  7. <script>
  8. import Loading from '@/common/Loading.vue'
  9. export default {
  10. name: 'BaseGeniusLine',
  11. components: {Loading},
  12. props: ['echartsId', 'echartsData'],
  13. data() {
  14. return {
  15. dataLoading:false,
  16. radarData: []
  17. }
  18. },
  19. methods: {
  20. drawLine(echartsData) {
  21. let that = this
  22. let myLine = this.$echarts.init(
  23. document.getElementById(this.echartsId),
  24. 'chalk'
  25. )
  26. // 指定图表的配置项和数据
  27. var option = {
  28. color: ['#00B2C1'],
  29. textStyle: {
  30. color: 'rgb(222,222,222)'
  31. },
  32. tooltip: {
  33. trigger: 'axis',
  34. axisPointer: {
  35. type: 'shadow'
  36. },
  37. formatter: function(params) {
  38. var results = params[0].name + '<br>'
  39. for (var i = 0; i < params.length; i++) {
  40. if (params[i].seriesType === 'line') {
  41. results += params[i].marker + params[i].seriesName + ':' + params[i].data + '%<br>'
  42. } else {
  43. results += params[i].marker + params[i].seriesName + ':' + params[i].data + '<br>'
  44. }
  45. }
  46. return results
  47. }
  48. },
  49. grid: {
  50. show: false,
  51. containLabel: true,
  52. height: 320,
  53. width: '98%',
  54. x2: '1%',
  55. tooltip: {
  56. show: true,
  57. trigger: 'axis', // 触发类型
  58. textStyle: {
  59. color: '#666'
  60. }
  61. }
  62. },
  63. dataZoom: [
  64. {
  65. show: true,
  66. height: 10,
  67. xAxisIndex: [0],
  68. bottom: 20,
  69. start: 0,
  70. end: 100,
  71. handleIcon:
  72. 'M512 497.821538m-418.264615 0a418.264615 418.264615 0 1 0 836.52923 0 418.264615 418.264615 0 1 0-836.52923 0Z',
  73. handleSize: '160%',
  74. handleStyle: {
  75. color: '#d3dee5'
  76. },
  77. textStyle: {
  78. color: '#fff'
  79. },
  80. borderColor: '#90979c'
  81. },
  82. {
  83. type: 'inside',
  84. show: true,
  85. height: 15,
  86. start: 0,
  87. end: 100
  88. }
  89. ],
  90. legend: {
  91. data: [this.$t('totalAnalysis.echarts_text18'), this.$t('totalAnalysis.echarts_text17')],
  92. textStyle: {
  93. color: '#FFFFFF'
  94. }
  95. },
  96. xAxis: [
  97. {
  98. data: echartsData.className,
  99. axisLine: {
  100. show: true,
  101. lineStyle: {
  102. color: '#4e4e4e'
  103. }
  104. },
  105. splitLine: {
  106. show: false
  107. },
  108. axisTick: {
  109. show: false
  110. },
  111. axisLabel: {
  112. show: true, // 是否显示
  113. inside: false, // 是否朝内
  114. rotate: 45, // 旋转角度
  115. margin: 15, // 刻度标签与轴线之间的距离
  116. color: '#989898', // 默认取轴线的颜色,
  117. fontSize: 12,
  118. fontFamily: 'Microsoft YaHei'
  119. }
  120. }
  121. ],
  122. yAxis: [
  123. {
  124. type: 'value',
  125. name: this.$t('totalAnalysis.echarts_text18'),
  126. axisLine: {
  127. show: false
  128. },
  129. axisTick: {
  130. show: false
  131. },
  132. splitLine: {
  133. show: false
  134. },
  135. axisLabel: {}
  136. },
  137. {
  138. type: 'value',
  139. name: this.$t('totalAnalysis.echarts_text17') + '(%)',
  140. axisLine: {
  141. show: false
  142. },
  143. axisTick: {
  144. show: false
  145. },
  146. splitLine: {
  147. show: false
  148. },
  149. axisLabel: {}
  150. }
  151. ],
  152. series: [
  153. {
  154. name: this.$t('totalAnalysis.echarts_text18'),
  155. type: 'bar',
  156. itemStyle: {
  157. normal: {
  158. // barBorderRadius: [30, 30, 0, 0],
  159. color: this.$echarts.graphic.LinearGradient(0, 1, 0, 0, [
  160. {
  161. offset: 0,
  162. color: '#00B2C1'
  163. },
  164. {
  165. offset: 1,
  166. color: '#00B2C1'
  167. }
  168. ])
  169. }
  170. },
  171. barMaxWidth:40,
  172. data: echartsData.KeyLines.map(item => item[1])
  173. },
  174. {
  175. name: this.$t('totalAnalysis.echarts_text17'),
  176. type: 'line',
  177. yAxisIndex: 1,
  178. symbol: 'circle',
  179. symbolSize:10,
  180. smooth: false,
  181. itemStyle: {
  182. normal: {
  183. color: '#ffe898',
  184. barBorderRadius: [30, 30, 0, 0],
  185. lineStyle: {
  186. color: '#ffe898'
  187. }
  188. }
  189. },
  190. data: echartsData.KeyLines.map(item => item[2]),
  191. markLine: {
  192. symbol: 'none',
  193. itemStyle: {
  194. normal: {
  195. lineStyle: {
  196. type: 'dashed',
  197. color: 'red'
  198. },
  199. label: {
  200. show: true,
  201. position: 'left'
  202. }
  203. }
  204. },
  205. large: true,
  206. effect: {
  207. show: false,
  208. loop: true,
  209. period: 0,
  210. scaleSize: 2,
  211. color: null,
  212. shadowColor: null,
  213. shadowBlur: null
  214. },
  215. data: [
  216. [
  217. {
  218. name: '',
  219. xAxis: '',
  220. yAxis: ''
  221. },
  222. {
  223. name: '',
  224. xAxis: '',
  225. yAxis: ''
  226. }
  227. ]
  228. ]
  229. }
  230. }
  231. ]
  232. }
  233. // 绘制图表
  234. myLine.setOption(option)
  235. window.addEventListener('resize', function() {
  236. myLine.resize()
  237. })
  238. myLine.on('finished', function () {
  239. if (that.dataLoading) {
  240. that.dataLoading = false
  241. }
  242. });
  243. }
  244. },
  245. mounted() {
  246. if (this.echartsData) this.drawLine()
  247. },
  248. watch: {
  249. echartsData(val) {
  250. if (!val) return
  251. this.drawLine(val)
  252. }
  253. }
  254. }
  255. </script>
  256. <!-- Add 'scoped' attribute to limit CSS to this component only -->
  257. <style scoped>
  258. .myLine {
  259. width: 100%;
  260. height: 420px;
  261. margin: 0 auto;
  262. display: block;
  263. }
  264. </style>