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

169 lines
4.0 KiB

  1. <template>
  2. <div id="main" :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: 'AcrossEcharts',
  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: '100%'
  25. }
  26. },
  27. data() {
  28. return {
  29. chart: null
  30. }
  31. },
  32. watch: {
  33. 'chartData': {
  34. handler(val) {
  35. setTimeout(() => {
  36. this.drawChart()
  37. }, 100)
  38. },
  39. immediate: true,
  40. deep: true
  41. }
  42. },
  43. mounted() {
  44. this.drawChart()
  45. window.addEventListener('resize', this.__resizeHandler)
  46. },
  47. methods: {
  48. drawChart() {
  49. const chartDom = document.getElementById('main')
  50. this.chart = echarts.init(chartDom)
  51. let option = null
  52. option = {
  53. grid: { // 边距
  54. left: '2%',
  55. right: '2%',
  56. bottom: '5%',
  57. top: '8%',
  58. containLabel: true
  59. },
  60. tooltip: {
  61. trigger: 'axis',
  62. axisPointer: {
  63. type: 'cross',
  64. label: {
  65. backgroundColor: '#339cff'
  66. }
  67. }
  68. },
  69. xAxis: {
  70. type: 'category',
  71. data: this.chartData.totalLendMonth,
  72. axisLine: { // 轴线的颜色以及宽度
  73. lineStyle: {
  74. color: 'rgba(17, 61, 114,0.5)'
  75. }
  76. },
  77. axisTick: { show: false },
  78. axisLabel: { // x轴文字的配置
  79. show: true,
  80. textStyle: {
  81. color: '#fff'
  82. }
  83. }
  84. },
  85. yAxis: {
  86. type: 'value',
  87. // min: 5000,
  88. // max: 25000,
  89. min: 0,
  90. max: function(value) {
  91. return Math.ceil(value.max + (value.max - value.min) * 0.2)
  92. },
  93. splitNumber: 5,
  94. axisLine: {
  95. show: false
  96. },
  97. axisLabel: { // x轴文字的配置
  98. show: true,
  99. textStyle: {
  100. color: '#fff'
  101. }
  102. },
  103. axisTick: { // 刻度线隐藏
  104. show: false
  105. },
  106. splitLine: { // 分割线配置
  107. lineStyle: {
  108. color: 'rgba(17, 61, 114,0.5)',
  109. type: 'solid'
  110. }
  111. }
  112. },
  113. series: [
  114. {
  115. name: '借阅量',
  116. data: this.chartData.totalLendData,
  117. type: 'line',
  118. areaStyle: {
  119. normal: {
  120. color: {
  121. x: 0,
  122. y: 0,
  123. x2: 0,
  124. y2: 1,
  125. colorStops: [
  126. {
  127. offset: 0.1,
  128. color: 'rgba(26, 201, 255, 0.5)' // 0% 处的颜色
  129. },
  130. {
  131. offset: 0.5,
  132. color: 'rgba(26, 201, 255, 0.3)' // 0% 处的颜色
  133. },
  134. {
  135. offset: 0.7,
  136. color: 'rgba(26, 201, 255, 0.2)' // 0% 处的颜色
  137. },
  138. {
  139. offset: 0.9,
  140. color: 'rgba(26, 201, 255, 0.1)' // 100% 处的颜色
  141. }
  142. ]
  143. }
  144. }
  145. },
  146. itemStyle: {
  147. normal: {
  148. color: '#339CFF', // 改变折线点的颜色
  149. lineStyle: {
  150. color: 'rgba(26, 201, 255,0.5)' // 改变折线颜色
  151. }
  152. }
  153. }
  154. }
  155. ]
  156. }
  157. option && this.chart.setOption(option)
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. .h{
  164. color: rgb(26, 201, 255);
  165. }
  166. </style>