BaseKnowledgeDetail.vue 4.4 KB

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