东西湖大屏
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
4.5 KiB

  1. <template>
  2. <div id="main2" :style="{height:height,width:width}" />
  3. </template>
  4. <script>
  5. import echarts from 'echarts'
  6. import resize from '@/utils/resizeMixins.js'
  7. export default {
  8. name: 'LineEcharts',
  9. mixins: [resize],
  10. props: {
  11. className: {
  12. type: String,
  13. default: ''
  14. },
  15. chartData: {
  16. type: Object,
  17. required: true
  18. },
  19. width: {
  20. type: String,
  21. default: '100%'
  22. },
  23. height: {
  24. type: String,
  25. default: 'calc(100% - 20px)'
  26. }
  27. },
  28. data() {
  29. return {
  30. chart: null
  31. }
  32. },
  33. watch: {
  34. chartData: {
  35. deep: true,
  36. handler(val) {
  37. this.setOptions(val)
  38. }
  39. }
  40. },
  41. mounted() {
  42. this.$nextTick(() => {
  43. this.initChart()
  44. })
  45. },
  46. beforeDestroy() {
  47. if (!this.chart) {
  48. return
  49. }
  50. this.chart.dispose()
  51. this.chart = null
  52. },
  53. methods: {
  54. initChart() {
  55. const dom = document.getElementById('main2')
  56. this.chart = echarts.init(dom, 'dark')
  57. this.setOptions(this.chartData)
  58. },
  59. setOptions({ returnData, borrowedData } = {}) {
  60. this.chart.setOption({
  61. backgroundColor: '#010326',
  62. tooltip: {
  63. trigger: 'axis',
  64. axisPointer: {
  65. type: 'cross',
  66. label: {
  67. backgroundColor: '#6a7985'
  68. }
  69. }
  70. },
  71. legend: {
  72. top: '4%',
  73. right: '4%',
  74. icon: 'rect',
  75. itemHeight: 4,
  76. itemWidth: 26,
  77. textStyle: {
  78. fontSize: '16px',
  79. color: '#339CFF'
  80. },
  81. data: ['借出', '归还']
  82. },
  83. grid: {
  84. left: '2%',
  85. right: '4%',
  86. bottom: '0',
  87. containLabel: true
  88. },
  89. xAxis: [{
  90. type: 'category',
  91. boundaryGap: false,
  92. // 坐标轴轴线相关设置
  93. axisLine: {
  94. show: true,
  95. lineStyle: {
  96. width: '1',
  97. color: '#113D72',
  98. type: 'solid'
  99. }
  100. },
  101. axisLabel: {
  102. fontWeight: 'bold',
  103. color: '#fff'
  104. },
  105. data: ['04:00', '08:00', '12:00', '16:00', '20:00', '24:00']
  106. }],
  107. yAxis: [
  108. {
  109. type: 'value',
  110. // 坐标轴最大值、最小值、强制设置数据的步长间隔
  111. max: 1000,
  112. min: 0,
  113. interval: 250,
  114. axisLabel: {
  115. textStyle: {
  116. color: '#fff',
  117. fontWeight: 'bold'
  118. }
  119. },
  120. // 轴线
  121. axisLine: {
  122. show: true,
  123. lineStyle: {
  124. color: '#113D72',
  125. width: '1',
  126. type: 'solid'
  127. }
  128. },
  129. // 坐标轴刻度相关设置。
  130. axisTick: {
  131. show: false
  132. },
  133. // 分割线
  134. splitLine: {
  135. show: true,
  136. lineStyle: {
  137. color: '#113D72',
  138. type: 'dashed',
  139. // 透明度
  140. opacity: 1,
  141. width: 1
  142. }
  143. }
  144. }
  145. ],
  146. series: [
  147. {
  148. name: '归还',
  149. type: 'line',
  150. smooth: 0.6,
  151. lineStyle: {
  152. width: 1,
  153. color: '#18B08F'
  154. },
  155. showSymbol: false,
  156. areaStyle: {
  157. opacity: 0.6,
  158. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  159. {
  160. offset: 0,
  161. color: 'rgba(24, 176, 143, 0)'
  162. },
  163. {
  164. offset: 1,
  165. color: 'rgba(23, 175, 142, 1)'
  166. }
  167. ])
  168. },
  169. data: returnData
  170. },
  171. {
  172. name: '借出',
  173. type: 'line',
  174. smooth: 0.4,
  175. lineStyle: {
  176. width: 1,
  177. color: '#FE8042'
  178. },
  179. showSymbol: false,
  180. areaStyle: {
  181. opacity: 0.6,
  182. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  183. {
  184. offset: 0,
  185. color: 'rgba(254, 128, 66, 0)'
  186. },
  187. {
  188. offset: 1,
  189. color: 'rgba(254, 128, 66, 1)'
  190. }
  191. ])
  192. },
  193. data: borrowedData
  194. }
  195. ]
  196. })
  197. }
  198. }
  199. }
  200. </script>