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

217 lines
5.0 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. 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({ 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: time.map(function(item) {
  95. return item
  96. }),
  97. axisLabel: {
  98. interval: 5,
  99. formatter: function(value, idx) {
  100. return value
  101. },
  102. color: '#fff'
  103. },
  104. axisLine: {
  105. lineStyle: {
  106. width: '1',
  107. color: '#113D72',
  108. type: 'solid'
  109. }
  110. },
  111. splitLine: {
  112. show: true,
  113. lineStyle: {
  114. color: '#333'
  115. }
  116. },
  117. boundaryGap: false
  118. }],
  119. yAxis: [
  120. {
  121. type: 'value',
  122. // 坐标轴最大值、最小值、强制设置数据的步长间隔
  123. // max: 1000,
  124. min: 0,
  125. max: function(value) {
  126. return Math.ceil(value.max + (value.max - value.min) * 0.2)
  127. },
  128. // interval: 250,
  129. splitNumber: 5,
  130. axisLabel: {
  131. textStyle: {
  132. color: '#fff'
  133. }
  134. },
  135. // 轴线
  136. axisLine: {
  137. show: true,
  138. lineStyle: {
  139. color: '#113D72',
  140. width: '1',
  141. type: 'solid'
  142. }
  143. },
  144. // 坐标轴刻度相关设置。
  145. axisTick: {
  146. show: false
  147. },
  148. // 分割线
  149. splitLine: {
  150. show: true,
  151. lineStyle: {
  152. color: '#113D72',
  153. type: 'dashed',
  154. // 透明度
  155. opacity: 1,
  156. width: 1
  157. }
  158. }
  159. }
  160. ],
  161. series: [
  162. {
  163. name: '归还',
  164. type: 'line',
  165. smooth: 0.6,
  166. lineStyle: {
  167. width: 1,
  168. color: '#18B08F'
  169. },
  170. showSymbol: false,
  171. areaStyle: {
  172. opacity: 0.6,
  173. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  174. {
  175. offset: 0,
  176. color: 'rgba(24, 176, 143, 0)'
  177. },
  178. {
  179. offset: 1,
  180. color: 'rgba(23, 175, 142, 1)'
  181. }
  182. ])
  183. },
  184. data: returnData
  185. },
  186. {
  187. name: '借出',
  188. type: 'line',
  189. smooth: 0.4,
  190. lineStyle: {
  191. width: 1,
  192. color: '#FE8042'
  193. },
  194. showSymbol: false,
  195. areaStyle: {
  196. opacity: 0.6,
  197. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  198. {
  199. offset: 0,
  200. color: 'rgba(254, 128, 66, 0)'
  201. },
  202. {
  203. offset: 1,
  204. color: 'rgba(254, 128, 66, 1)'
  205. }
  206. ])
  207. },
  208. data: borrowedData
  209. }
  210. ]
  211. })
  212. }
  213. }
  214. }
  215. </script>