BaseLineBar.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <div id="stuAverageBar"></div>
  3. </template>
  4. <script>
  5. export default {
  6. name: 'hello',
  7. props: ['echartData', 'exerciseIndex'],
  8. data() {
  9. return {
  10. echartDatas: [],
  11. currentExerciseIndex: 0
  12. }
  13. },
  14. created() {
  15. },
  16. methods: {
  17. drawLine(echartData, exerciseIndex) {
  18. let that = this
  19. let myBar = this.$echarts.init(document.getElementById('stuAverageBar'))
  20. var option = {
  21. legend: {
  22. data: [{
  23. name: that.$t('totalAnalysis.ta_chart_text4'),
  24. textStyle: {
  25. color: '#fff'
  26. }
  27. },
  28. {
  29. name: that.$t('totalAnalysis.ta_chart_text5'),
  30. color: 'red',
  31. textStyle: {
  32. color: '#fff'
  33. }
  34. },
  35. {
  36. name: that.$t('totalAnalysis.ta_chart_text6'),
  37. color: 'red',
  38. textStyle: {
  39. color: '#fff'
  40. }
  41. }
  42. ]
  43. },
  44. tooltip: {
  45. show: true, // 是否显示提示框,默认为true
  46. trigger: 'axis', // 数据项图形触发
  47. axisPointer: {
  48. // 指示样式
  49. type: 'shadow',
  50. axis: 'auto',
  51. shadowStyle: {
  52. color: 'rgba(128,128,128,0.1)'
  53. }
  54. },
  55. padding: 5,
  56. textStyle: {
  57. color: '#fff'
  58. },
  59. formatter: function(params) {
  60. let result = params[0].name
  61. for (let i = 0; i < params.length; i++) {
  62. result += '<br>' + params[i].marker + params[i].seriesName + ':' + params[i].data + '%'
  63. }
  64. return result
  65. }
  66. },
  67. grid: {
  68. show: false,
  69. containLabel: true,
  70. height: 460,
  71. width: '90%',
  72. x2: '5%',
  73. tooltip: {
  74. show: true,
  75. trigger: 'axis', // 触发类型
  76. textStyle: {
  77. color: '#666'
  78. }
  79. }
  80. },
  81. dataZoom: [{
  82. 'show': true,
  83. 'height': 10,
  84. 'xAxisIndex': [
  85. 0
  86. ],
  87. bottom: 30,
  88. 'start': 0,
  89. 'end': 100,
  90. handleIcon: 'M512 497.821538m-418.264615 0a418.264615 418.264615 0 1 0 836.52923 0 418.264615 418.264615 0 1 0-836.52923 0Z',
  91. handleSize: '160%',
  92. handleStyle: {
  93. color: '#d3dee5'
  94. },
  95. textStyle: {
  96. color: '#fff'
  97. },
  98. borderColor: '#90979c'
  99. }, {
  100. 'type': 'inside',
  101. 'show': true,
  102. 'height': 15,
  103. 'start': 0,
  104. 'end': 100
  105. }],
  106. xAxis: {
  107. show: true,
  108. offset: 0,
  109. type: 'category',
  110. axisLabel: {
  111. show: true,
  112. inside: false,
  113. margin: 15,
  114. color: '#989898'
  115. },
  116. data: echartData.map(item => item.className)
  117. },
  118. yAxis: {
  119. show: true,
  120. type: 'value',
  121. min: 0,
  122. max: 100,
  123. axisLabel: {
  124. show: true,
  125. inside: false,
  126. rotate: 0,
  127. margin: 8,
  128. color: '#989898',
  129. formatter: '{value} %',
  130. fontSize: 12,
  131. fontFamily: 'Microsoft YaHei'
  132. },
  133. splitLine: {
  134. show: true,
  135. lineStyle: {
  136. color: '#4c504a',
  137. width: 0.5,
  138. type: 'solid'
  139. }
  140. }
  141. },
  142. series: [
  143. {
  144. name: that.$t('totalAnalysis.ta_chart_text4'),
  145. type: 'bar',
  146. itemStyle: {
  147. normal: { // 渐变色
  148. color: '#66cccc'
  149. },
  150. width: 20
  151. },
  152. markPoint: {
  153. data: [
  154. { type: 'max', name: '最大值' },
  155. { type: 'min', name: '最小值' }
  156. ]
  157. },
  158. data: echartData.map(item => item.datas[exerciseIndex])
  159. },
  160. {
  161. name: that.$t('totalAnalysis.ta_chart_text5'),
  162. type: 'line',
  163. itemStyle: {
  164. color: '#ff33cc',
  165. width: 0
  166. },
  167. symbol: 'none',
  168. lineStyle: {
  169. type: 'dashed',
  170. width: 0
  171. },
  172. markLine: {
  173. data: [
  174. { type: 'average' }
  175. ],
  176. lineStyle: {
  177. color: '#ff33cc',
  178. type: 'dashed'
  179. }
  180. },
  181. data: echartData.map(item => this.gradeRate)
  182. },
  183. {
  184. name: that.$t('totalAnalysis.ta_chart_text6'),
  185. type: 'line',
  186. itemStyle: {
  187. color: '#66ff99',
  188. width: 0
  189. },
  190. symbol: 'none',
  191. lineStyle: {
  192. type: 'dashed',
  193. width: 0
  194. },
  195. markLine: {
  196. data: [
  197. { type: 'average' }
  198. ],
  199. lineStyle: {
  200. color: '#66ff99',
  201. type: 'dashed'
  202. }
  203. },
  204. data: echartData.map(item => this.areaRate)
  205. }
  206. ]
  207. }
  208. // 绘制图表
  209. myBar.setOption(option)
  210. window.addEventListener('resize', function() {
  211. myBar.resize()
  212. })
  213. },
  214. // 监听变化处理重新渲染
  215. doRender(data) {
  216. let exerciseData = this.$store.state.totalAnalysis.exerciseData
  217. if (!data || !exerciseData) return
  218. this.gradeRate = exerciseData[this.currentExerciseIndex].gradeScoreRate
  219. this.areaRate = exerciseData[this.currentExerciseIndex].areaScoreRate
  220. this.drawLine(data, this.currentExerciseIndex)
  221. }
  222. },
  223. mounted() {
  224. if (this.getClassExerciseData) {
  225. this.doRender(this.getClassExerciseData)
  226. }
  227. },
  228. computed: {
  229. // 获取最新柱状图数据
  230. getClassExerciseData() {
  231. return this.$store.state.totalAnalysis.classExerciseData
  232. }
  233. },
  234. watch: {
  235. getClassExerciseData(val) {
  236. if (!val) return
  237. this.doRender(val)
  238. },
  239. exerciseIndex(val) {
  240. if (val) {
  241. this.currentExerciseIndex = +val - 1 // 拿到当前所选择的题号 确认数据下标
  242. this.doRender(this.getClassExerciseData)
  243. }
  244. }
  245. }
  246. }
  247. </script>
  248. <!-- Add "scoped" attribute to limit CSS to this component only -->
  249. <style scoped>
  250. #stuAverageBar {
  251. width: 100%;
  252. height: 600px;
  253. margin: 0 auto;
  254. display: block;
  255. }
  256. </style>