keyboard.vue 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div :class="className" :id="id" :style="{height:height,width:width}"></div>
  3. </template>
  4. <script>
  5. import echarts from 'echarts'
  6. import resize from './mixins/resize'
  7. export default {
  8. mixins: [resize],
  9. props: {
  10. className: {
  11. type: String,
  12. default: 'chart'
  13. },
  14. id: {
  15. type: String,
  16. default: 'chart'
  17. },
  18. width: {
  19. type: String,
  20. default: '200px'
  21. },
  22. height: {
  23. type: String,
  24. default: '200px'
  25. }
  26. },
  27. data() {
  28. return {
  29. chart: null
  30. }
  31. },
  32. mounted() {
  33. this.initChart()
  34. },
  35. beforeDestroy() {
  36. if (!this.chart) {
  37. return
  38. }
  39. this.chart.dispose()
  40. this.chart = null
  41. },
  42. methods: {
  43. initChart() {
  44. this.chart = echarts.init(document.getElementById(this.id))
  45. const xAxisData = []
  46. const data = []
  47. const data2 = []
  48. for (let i = 0; i < 50; i++) {
  49. xAxisData.push(i)
  50. data.push((Math.sin(i / 5) * (i / 5 - 10) + i / 6) * 5)
  51. data2.push((Math.sin(i / 5) * (i / 5 + 10) + i / 6) * 3)
  52. }
  53. this.chart.setOption(
  54. {
  55. backgroundColor: '#08263a',
  56. xAxis: [{
  57. show: false,
  58. data: xAxisData
  59. }, {
  60. show: false,
  61. data: xAxisData
  62. }],
  63. visualMap: {
  64. show: false,
  65. min: 0,
  66. max: 50,
  67. dimension: 0,
  68. inRange: {
  69. color: ['#4a657a', '#308e92', '#b1cfa5', '#f5d69f', '#f5898b', '#ef5055']
  70. }
  71. },
  72. yAxis: {
  73. axisLine: {
  74. show: false
  75. },
  76. axisLabel: {
  77. textStyle: {
  78. color: '#4a657a'
  79. }
  80. },
  81. splitLine: {
  82. show: true,
  83. lineStyle: {
  84. color: '#08263f'
  85. }
  86. },
  87. axisTick: {
  88. show: false
  89. }
  90. },
  91. series: [{
  92. name: 'back',
  93. type: 'bar',
  94. data: data2,
  95. z: 1,
  96. itemStyle: {
  97. normal: {
  98. opacity: 0.4,
  99. barBorderRadius: 5,
  100. shadowBlur: 3,
  101. shadowColor: '#111'
  102. }
  103. }
  104. }, {
  105. name: 'Simulate Shadow',
  106. type: 'line',
  107. data,
  108. z: 2,
  109. showSymbol: false,
  110. animationDelay: 0,
  111. animationEasing: 'linear',
  112. animationDuration: 1200,
  113. lineStyle: {
  114. normal: {
  115. color: 'transparent'
  116. }
  117. },
  118. areaStyle: {
  119. normal: {
  120. color: '#08263a',
  121. shadowBlur: 50,
  122. shadowColor: '#000'
  123. }
  124. }
  125. }, {
  126. name: 'front',
  127. type: 'bar',
  128. data,
  129. xAxisIndex: 1,
  130. z: 3,
  131. itemStyle: {
  132. normal: {
  133. barBorderRadius: 5
  134. }
  135. }
  136. }],
  137. animationEasing: 'elasticOut',
  138. animationEasingUpdate: 'elasticOut',
  139. animationDelay(idx) {
  140. return idx * 20
  141. },
  142. animationDelayUpdate(idx) {
  143. return idx * 20
  144. }
  145. })
  146. }
  147. }
  148. }
  149. </script>