BaseLineBar.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <div id="stuAverageBar"></div>
  3. </template>
  4. <script>
  5. export default {
  6. name: "hello",
  7. props: ['echartData'],
  8. data() {
  9. return {
  10. echartDatas: [],
  11. gradeRate: 62.4,
  12. areaRate:76.2
  13. };
  14. },
  15. created() {
  16. },
  17. mounted() {
  18. this.drawLine(this.echartData);
  19. },
  20. methods: {
  21. drawLine(echartData) {
  22. let myBar = this.$echarts.init(document.getElementById("stuAverageBar"));
  23. var option = {
  24. legend: {
  25. data: [{
  26. name: '班级得分率',
  27. textStyle: {
  28. color: '#fff'
  29. }
  30. },
  31. {
  32. name: '年级得分率',
  33. color: "red",
  34. textStyle: {
  35. color: '#fff'
  36. }
  37. },
  38. {
  39. name: '区级得分率',
  40. color: "red",
  41. textStyle: {
  42. color: '#fff'
  43. }
  44. }
  45. ]
  46. },
  47. tooltip: {
  48. show: true, // 是否显示提示框,默认为true
  49. trigger: "axis", // 数据项图形触发
  50. axisPointer: {
  51. // 指示样式
  52. type: "shadow",
  53. axis: "auto",
  54. shadowStyle: {
  55. color: "rgba(128,128,128,0.1)"
  56. }
  57. },
  58. padding: 5,
  59. textStyle: {
  60. color: "#fff"
  61. },
  62. formatter: function (params) {
  63. return params[0].name + '<br>'
  64. + params[0].marker + params[0].seriesName + ':' + params[0].data + '%<br>'
  65. + params[1].marker + params[1].seriesName + ':'+ params[1].data + '%<br>'
  66. + params[2].marker + params[2].seriesName + ':'+ params[2].data + '%<br>'
  67. }
  68. },
  69. grid: {
  70. top: 80, // 相对位置 top\bottom\left\right
  71. },
  72. dataZoom: {
  73. show: true,
  74. realtime: true,
  75. type: "inside",
  76. },
  77. //toolbox: {
  78. // show: true,
  79. // feature: {
  80. // magicType: { show: true, type: ['line', 'bar'] },
  81. // saveAsImage: { show: true }
  82. // }
  83. //},
  84. xAxis: {
  85. show: true,
  86. offset: 0,
  87. type: "category",
  88. axisLabel: {
  89. show: true,
  90. inside: false,
  91. margin: 15,
  92. color: "#989898",
  93. },
  94. data: echartData.map(item => item.name)
  95. },
  96. yAxis: {
  97. show: true,
  98. type: "value",
  99. min: 0,
  100. max:100,
  101. axisLabel: {
  102. show: true,
  103. inside: false,
  104. rotate: 0,
  105. margin: 8,
  106. color: "#989898",
  107. formatter: '{value} %',
  108. fontSize: 12,
  109. fontFamily: "Microsoft YaHei"
  110. },
  111. splitLine: {
  112. show: true,
  113. lineStyle: {
  114. color: "#4c504a",
  115. width: 0.5,
  116. type: "solid"
  117. }
  118. }
  119. },
  120. series: [
  121. {
  122. name:'班级得分率',
  123. type: "bar",
  124. itemStyle: {
  125. normal: { //渐变色
  126. color: '#66cccc'
  127. },
  128. width: 20,
  129. },
  130. markPoint : {
  131. data : [
  132. {type : 'max', name: '最大值'},
  133. {type : 'min', name: '最小值'}
  134. ],
  135. },
  136. barWidth:50,
  137. data: echartData.map(item => item.entryRate)
  138. },
  139. {
  140. name:'年级得分率',
  141. type: "line",
  142. itemStyle: {
  143. color: "#ff33cc",
  144. width: 0,
  145. },
  146. symbol: 'none',
  147. lineStyle: {
  148. type: "dashed",
  149. width: 0,
  150. },
  151. markLine: {
  152. data: [
  153. { type: 'average' }
  154. ],
  155. lineStyle: {
  156. color: '#ff33cc',
  157. type: "dashed"
  158. }
  159. },
  160. data: echartData.map(item => this.gradeRate)
  161. },
  162. {
  163. name:'区级得分率',
  164. type: "line",
  165. itemStyle: {
  166. color: "#66ff99",
  167. width: 0,
  168. },
  169. symbol: 'none',
  170. lineStyle: {
  171. type: "dashed",
  172. width: 0,
  173. },
  174. markLine: {
  175. data: [
  176. { type: 'average' }
  177. ],
  178. lineStyle: {
  179. color: '#66ff99',
  180. type: "dashed"
  181. }
  182. },
  183. data: echartData.map(item => this.areaRate)
  184. },
  185. ]
  186. };
  187. // 绘制图表
  188. myBar.setOption(option);
  189. window.addEventListener("resize", function () {
  190. myBar.resize();
  191. });
  192. }
  193. }
  194. };
  195. </script>
  196. <!-- Add "scoped" attribute to limit CSS to this component only -->
  197. <style scoped>
  198. #stuAverageBar {
  199. width: 100%;
  200. height: 600px;
  201. margin: 0 auto;
  202. display: block;
  203. }
  204. </style>