祁阳图书馆智慧大屏
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.

263 lines
6.4 KiB

12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
  1. <template>
  2. <div ref="lineContainer" :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. chartDayData: {
  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: '100%'
  25. }
  26. },
  27. data() {
  28. return {
  29. chart: null,
  30. option: null
  31. }
  32. },
  33. watch: {
  34. chartDayData: {
  35. deep: true,
  36. mmediate: true,
  37. handler(val) {
  38. setTimeout(() => {
  39. this.initChart()
  40. }, 100)
  41. }
  42. }
  43. },
  44. beforeDestroy() {
  45. if (!this.chart) {
  46. return
  47. }
  48. this.chart.dispose()
  49. this.chart = null
  50. },
  51. mounted() {
  52. this.$nextTick(() => {
  53. this.initChart()
  54. })
  55. window.addEventListener('resize', this.__resizeHandler)
  56. this.resetPiechartDayData()
  57. },
  58. methods: {
  59. resetPiechartDayData() {
  60. clearInterval(this.timeRePie)
  61. this.timeRePie = setInterval(() => {
  62. // debugger;
  63. if (!this.chart) {
  64. return
  65. }
  66. // 不先清空chart没法重绘
  67. this.chart.clear()
  68. this.initChart()
  69. }, 8000)
  70. },
  71. initChart() {
  72. // const dom = document.getElementById('main2')
  73. const dom = this.$refs.lineContainer
  74. this.chart = echarts.init(dom, 'dark')
  75. this.setOptions(this.chartDayData)
  76. },
  77. setOptions({ timeData, returnData, borrowedData } = {}) {
  78. this.chart.setOption({
  79. backgroundColor: '#01103D',
  80. tooltip: {
  81. trigger: 'axis',
  82. axisPointer: {
  83. type: 'cross',
  84. label: {
  85. backgroundColor: '#6a7985'
  86. }
  87. }
  88. },
  89. legend: {
  90. top: '4%',
  91. right: '4%',
  92. icon: 'rect',
  93. itemHeight: 6,
  94. itemWidth: 11,
  95. textStyle: {
  96. color: '#339CFF',
  97. fontSize: 18
  98. },
  99. data: [
  100. {
  101. name: '借出',
  102. icon: 'rect',
  103. textStyle: {
  104. color: '#41A3FF',
  105. fontFamily: 'DingTalk_JinBuTi_Regular'
  106. }
  107. },
  108. {
  109. name: '归还',
  110. icon: 'rect',
  111. textStyle: {
  112. color: '#FFD050',
  113. fontFamily: 'DingTalk_JinBuTi_Regular'
  114. }
  115. }
  116. ]
  117. },
  118. grid: {
  119. left: '2%',
  120. right: '4%',
  121. bottom: '4%',
  122. containLabel: true
  123. },
  124. xAxis: [{
  125. type: 'category',
  126. data: timeData,
  127. axisLabel: {
  128. show: true,
  129. formatter: function(value, idx) {
  130. return value
  131. },
  132. color: '#79B8FF',
  133. fontSize: 16,
  134. fontFamily: 'DingTalk_JinBuTi_Regular'
  135. },
  136. axisLine: {
  137. show: false,
  138. lineStyle: {
  139. width: '1',
  140. color: '#113D72',
  141. type: 'solid'
  142. }
  143. },
  144. axisTick: {
  145. show: false
  146. },
  147. splitLine: {
  148. show: false,
  149. lineStyle: {
  150. color: '#333'
  151. }
  152. },
  153. boundaryGap: false
  154. }],
  155. yAxis: [
  156. {
  157. type: 'value',
  158. // 坐标轴最大值、最小值、强制设置数据的步长间隔
  159. max: function(value) {
  160. return Math.ceil(value.max + (value.max - value.min) * 0.2)
  161. },
  162. min: 0,
  163. axisLabel: {
  164. interval: 'auto',
  165. formatter: function(value) {
  166. // 使用formatter保证即使在缩放时也只显示整数
  167. return Math.round(value)
  168. },
  169. textStyle: {
  170. color: '#79B8FF',
  171. fontSize: 16,
  172. fontFamily: 'DingTalk_JinBuTi_Regular'
  173. }
  174. },
  175. // 轴线
  176. axisLine: {
  177. show: false,
  178. lineStyle: {
  179. color: '#113D72',
  180. width: '1',
  181. type: 'solid'
  182. }
  183. },
  184. // 坐标轴刻度相关设置。
  185. axisTick: {
  186. show: false
  187. },
  188. // 分割线
  189. splitLine: {
  190. show: true,
  191. lineStyle: {
  192. color: 'rgba(66, 139, 221, 0.2)',
  193. type: 'solid',
  194. // 透明度
  195. opacity: 1,
  196. width: 1
  197. }
  198. }
  199. }
  200. ],
  201. series: [
  202. {
  203. name: '借出',
  204. type: 'line',
  205. stack: 'Total',
  206. itemStyle: {
  207. color: '#41A3FF'
  208. },
  209. lineStyle: {
  210. width: 3,
  211. color: '#41A3FF'
  212. },
  213. showSymbol: false,
  214. areaStyle: {
  215. opacity: 0.6,
  216. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  217. {
  218. offset: 0,
  219. color: 'rgba(254, 128, 66, 0)'
  220. },
  221. {
  222. offset: 1,
  223. color: '#41A3FF'
  224. }
  225. ])
  226. },
  227. data: borrowedData
  228. },
  229. {
  230. name: '归还',
  231. type: 'line',
  232. stack: 'Total',
  233. lineStyle: {
  234. width: 3,
  235. color: '#FFD14F'
  236. },
  237. showSymbol: false,
  238. itemStyle: {
  239. color: '#FFD14F'
  240. },
  241. areaStyle: {
  242. opacity: 0.6,
  243. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  244. {
  245. offset: 0,
  246. color: 'rgba(24, 176, 143, 0)'
  247. },
  248. {
  249. offset: 1,
  250. color: '#FFD14F'
  251. }
  252. ])
  253. },
  254. data: returnData
  255. }
  256. ]
  257. })
  258. }
  259. }
  260. }
  261. </script>