stackMap.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <div :class="className" :style="{height:height,width:width}" />
  3. </template>
  4. <script>
  5. import echarts from 'echarts'
  6. require('echarts/theme/macarons') // echarts theme
  7. const animationDuration = 3000
  8. export default {
  9. name: "stackMap",
  10. props: {
  11. className: {
  12. type: String,
  13. default: 'chart'
  14. },
  15. width: {
  16. type: String,
  17. default: '100%'
  18. },
  19. height: {
  20. type: String,
  21. default: '300px'
  22. }
  23. },
  24. data() {
  25. return {
  26. chart: null
  27. }
  28. },
  29. mounted() {
  30. this.initChart()
  31. /* this.__resizeHandler = debounce(() => {
  32. if (this.chart) {
  33. this.chart.resize()
  34. }
  35. }, 100)
  36. window.addEventListener('resize', this.__resizeHandler)*/
  37. },
  38. beforeDestroy() {
  39. if (!this.chart) {
  40. return
  41. }
  42. // window.removeEventListener('resize', this.__resizeHandler)
  43. this.chart.dispose()
  44. this.chart = null
  45. },
  46. methods: {
  47. initChart() {
  48. this.chart = echarts.init(this.$el, 'light')
  49. this.chart.setOption({
  50. tooltip: {
  51. trigger: 'axis',
  52. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  53. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  54. }
  55. },
  56. legend: {
  57. data: ['Javascript', 'Java', 'Python', 'Ruby', 'PHP']
  58. },
  59. grid: {
  60. left: '3%',
  61. right: '4%',
  62. bottom: '3%',
  63. containLabel: true
  64. },
  65. xAxis: {
  66. type: 'value',
  67. axisLabel: {
  68. show: true,
  69. textStyle: {
  70. color: 'rgb(192,192,192)', //更改坐标轴文字颜色
  71. fontSize : 12 //更改坐标轴文字大小
  72. }
  73. },
  74. axisTick: {
  75. show: false
  76. },
  77. axisLine:{
  78. lineStyle:{
  79. color:'rgb(192,192,192)' //更改坐标轴颜色
  80. }
  81. },
  82. },
  83. yAxis: {
  84. type: 'category',
  85. data: ['Mon', 'Tue', 'Wen', 'Thu', 'Fri', 'Sat', 'Sun'],
  86. axisLabel: {
  87. show: true,
  88. textStyle: {
  89. color: 'rgb(192,192,192)', //更改坐标轴文字颜色
  90. fontSize: 12 //更改坐标轴文字大小
  91. }
  92. },
  93. axisTick: {
  94. show: false
  95. },
  96. axisLine: {
  97. lineStyle: {
  98. color: 'rgb(192,192,192)' //更改坐标轴颜色
  99. }
  100. }
  101. },
  102. series: [
  103. {
  104. name: 'Javascript',
  105. type: 'bar',
  106. stack: '总量',
  107. label: {
  108. show: true,
  109. position: 'insideRight'
  110. },
  111. data: [320, 302, 301, 334, 390, 330, 320]
  112. },
  113. {
  114. name: 'Java',
  115. type: 'bar',
  116. stack: '总量',
  117. label: {
  118. show: true,
  119. position: 'insideRight'
  120. },
  121. data: [120, 132, 101, 134, 90, 230, 210]
  122. },
  123. {
  124. name: 'Python',
  125. type: 'bar',
  126. stack: '总量',
  127. label: {
  128. show: true,
  129. position: 'insideRight'
  130. },
  131. data: [220, 182, 191, 234, 290, 330, 310]
  132. },
  133. {
  134. name: 'Ruby',
  135. type: 'bar',
  136. stack: '总量',
  137. label: {
  138. show: true,
  139. position: 'insideRight'
  140. },
  141. data: [150, 212, 201, 154, 190, 330, 410]
  142. },
  143. {
  144. name: 'PHP',
  145. type: 'bar',
  146. stack: '总量',
  147. label: {
  148. show: true,
  149. position: 'insideRight'
  150. },
  151. data: [820, 832, 901, 934, 1290, 1330, 1320]
  152. }
  153. ],
  154. animationDuration: animationDuration
  155. })
  156. }
  157. }
  158. }
  159. </script>
  160. <style scoped>
  161. </style>