BaseKnowledgeBar.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <div class="knowledgeBar"></div>
  3. </template>
  4. <script>
  5. export default {
  6. props: ['echartData'],
  7. data() {
  8. return {
  9. x: ['方程与不等式', '图形的性质', '统计与概率', '函数', '图形的变化'],
  10. y:[28,10,23,25,12]
  11. };
  12. },
  13. mounted() {
  14. this.drawLine();
  15. },
  16. methods: {
  17. drawLine() {
  18. // 基于准备好的dom,初始化echarts实例
  19. let myBar = this.$echarts.init(document.getElementsByClassName("knowledgeBar")[0]);
  20. // 指定图表的配置项和数据
  21. var option = {
  22. tooltip: {
  23. show: true, // 是否显示提示框,默认为true
  24. trigger: "axis", // 数据项图形触发
  25. axisPointer: {
  26. // 指示样式
  27. type: "shadow",
  28. axis: "auto",
  29. shadowStyle: {
  30. color: "rgba(128,128,128,0.1)"
  31. }
  32. },
  33. padding: 5,
  34. textStyle: {
  35. // 提示框内容的样式
  36. color: "#fff"
  37. }
  38. },
  39. // ---- gird区域 ---
  40. grid: {
  41. show: false, // 是否显示直角坐标系网格
  42. top: 30, // 相对位置 top\bottom\left\right
  43. height:430,
  44. containLabel: true, // gird 区域是否包含坐标轴的刻度标签
  45. },
  46. dataZoom: {
  47. show: true,
  48. realtime: true,
  49. type: "inside",
  50. },
  51. xAxis: {
  52. show: true, // 是否显示
  53. position: "bottom", // x轴的位置
  54. offset: 0, // x轴相对于默认位置的偏移
  55. type: "category", // 轴类型, 默认为 'category'
  56. name: "月份", // 轴名称
  57. nameLocation: "end", // 轴名称相对位置
  58. nameTextStyle: {
  59. color: "transparent",
  60. padding: [5, 0, 10, -5]
  61. },
  62. nameGap: 35, // 坐标轴名称与轴线之间的距离
  63. nameRotate: 0, // 坐标轴名字旋转
  64. axisLabel: {
  65. // 坐标轴标签
  66. show: true, // 是否显示
  67. inside: false, // 是否朝内
  68. margin: 15,
  69. rotate:60,
  70. color: "#989898", // 默认取轴线的颜色,
  71. },
  72. splitLine: {
  73. show: false,
  74. lineStyle: {
  75. color: '#4c504a',
  76. }
  77. },
  78. splitArea: {
  79. show: false // 是否显示,默认为false
  80. },
  81. data: this.x
  82. },
  83. yAxis: {
  84. show: true, // 是否显示
  85. position: "left", // y轴位置
  86. offset: 0, // y轴相对于默认位置的偏移
  87. type: "value", // 轴类型,默认为 ‘category’
  88. nameLocation: "end", // 轴名称相对位置value
  89. nameTextStyle: {
  90. color: "#fff",
  91. padding: [5, 0, 0, 5] // 坐标轴名称相对位置
  92. },
  93. nameGap: 15, // 坐标轴名称与轴线之间的距离
  94. nameRotate: 270, // 坐标轴名字旋转
  95. axisLine: {
  96. show: false, // 是否显示
  97. lineStyle: {
  98. color: "#595959",
  99. width: 1,
  100. type: "solid"
  101. }
  102. },
  103. axisLabel: {
  104. show: true, // 是否显示
  105. inside: false, // 是否朝内
  106. rotate: 0, // 旋转角度
  107. margin: 8, // 刻度标签与轴线之间的距离
  108. color: "#989898", // 默认轴线的颜色
  109. fontSize: 12,
  110. formatter: '{value} %' ,
  111. },
  112. splitLine: {
  113. show: true,
  114. lineStyle: {
  115. color: "#4c504a",
  116. width: 0.5,
  117. type: "solid"
  118. }
  119. }
  120. },
  121. series: [
  122. {
  123. type: "bar",
  124. itemStyle: {
  125. color: "#4ad8f1",
  126. width: 20,
  127. },
  128. barWidth:30,
  129. data:this.y
  130. }]
  131. };
  132. // 绘制图表
  133. myBar.setOption(option);
  134. window.addEventListener("resize", function() {
  135. myBar.resize();
  136. });
  137. let that = this;
  138. myBar.on('click', function (params) {
  139. let className = params.name;
  140. if (className == "高二5班") {
  141. //that.$router.push('')
  142. that.$router.push({path: '/total/achievement/entryTables', replace: true})
  143. } else {
  144. that.$Message.warning("暂不支持查看其它班级数据!")
  145. }
  146. })
  147. }
  148. }
  149. };
  150. </script>
  151. <!-- Add "scoped" attribute to limit CSS to this component only -->
  152. <style scoped>
  153. .knowledgeBar {
  154. width: 100%;
  155. height: 460px;
  156. margin: 0 auto;
  157. display: block;
  158. }
  159. </style>