CourseBar.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <div :id="id" style="height: 100%;width:100%;"></div>
  3. </template>
  4. <script>
  5. export default {
  6. data() {
  7. return {
  8. myChart: ''
  9. }
  10. },
  11. props: {
  12. id: {
  13. type: String
  14. },
  15. data: {
  16. type: Object,
  17. default: function() {
  18. return { '模擬測驗': 0, '成績登錄': 5, '線上測驗': 16, 'HiTeach': 150, '合併活動': 6, '班級競賽': 23, '網路閱卷': 21 }
  19. }
  20. },
  21. callBack: {
  22. type: String
  23. }
  24. },
  25. mounted() {
  26. this.drawLine()
  27. },
  28. methods: {
  29. drawLine() {
  30. let _this = this
  31. // 取得x軸Label
  32. let xLabel = Object.keys(this.data)
  33. let courseDataArray = []
  34. let max
  35. // 資料統整
  36. xLabel.map(function(key) {
  37. courseDataArray.push(_this.data[key])
  38. })
  39. max = Math.max(...courseDataArray) + 20
  40. // 基于准备好的dom,初始化echarts实例
  41. this.myChart = this.$echarts.init(document.getElementById(this.id))
  42. this.myChart.setOption({
  43. backgroundColor: '#343a4073',
  44. tooltip: {
  45. trigger: 'axis',
  46. axisPointer: {
  47. type: 'shadow'
  48. },
  49. formatter: function(params) {
  50. // 故意開啟 但不設定使ToolTip 沒有彈跳的作用 但有Hover 功能
  51. }
  52. },
  53. grid: {
  54. left: '0',
  55. right: '2%',
  56. bottom: '1px',
  57. top: '0',
  58. containLabel: true
  59. },
  60. xAxis: {
  61. type: 'category',
  62. boundaryGap: false,
  63. data: xLabel,
  64. boundaryGap: ['20%', '20%'],
  65. axisLabel: {
  66. inside: true,
  67. textStyle: {
  68. color: 'transparent'
  69. }
  70. },
  71. axisLine: {
  72. show: true,
  73. lineStyle: {
  74. width: 1,
  75. color: 'rgba(185, 193, 173, 0.63)'
  76. }
  77. },
  78. splitLine: {
  79. show: true,
  80. lineStyle: {
  81. width: 1,
  82. color: 'rgba(185, 193, 173, 0.63)'
  83. }
  84. }
  85. },
  86. yAxis: {
  87. type: 'value',
  88. max: max,
  89. minInterval: 1,
  90. axisLabel: {
  91. inside: true,
  92. textStyle: {
  93. color: 'transparent'
  94. }
  95. },
  96. axisLine: {
  97. show: true,
  98. lineStyle: {
  99. width: 1,
  100. color: 'rgba(185, 193, 173, 0.63)'
  101. }
  102. },
  103. splitLine: {
  104. show: true,
  105. lineStyle: {
  106. width: 1,
  107. color: 'rgba(185, 193, 173, 0.63)'
  108. }
  109. }
  110. },
  111. series: [
  112. {
  113. // name: 'today',
  114. type: 'bar',
  115. data: courseDataArray,
  116. barWidth: 10, // 柱子宽度
  117. barGap: 1, // 柱子之间间距
  118. itemStyle: {
  119. normal: { // 渐变色
  120. color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  121. offset: 0,
  122. color: 'rgba(228, 233, 220, 1)' // 0% 处的颜色
  123. }, {
  124. offset: 1,
  125. color: 'rgba(228, 233, 220, 0.5)' // 100% 处的颜色
  126. }], false)
  127. }
  128. }
  129. }
  130. ]
  131. })
  132. }
  133. }
  134. }
  135. </script>
  136. <style>
  137. </style>