东西湖大屏
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.

216 lines
5.0 KiB

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