technologyBar.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 {'计分板': 100, '挑人': 30, '计时器': 28, '抢权': 25, '统计图':24, '即问即答':23, '作品比较':21, '推送':8, '翻牌':6, '二次作答':2}
  19. }
  20. },
  21. callBack: {
  22. type: String
  23. }
  24. },
  25. mounted(){
  26. this.drawLine();
  27. },
  28. methods:{
  29. drawLine(){
  30. let barcolor = ['#FF6B6A', '#FF9FF4', '#48DBFC', '#1CD0A1', '#FDC958', '#FFAD76'];
  31. let _this = this
  32. // 取得x轴Label
  33. let xLabel = Object.keys(this.data);
  34. let courseDataArray = [];
  35. let max;
  36. // 资料统整
  37. xLabel.map(function(key) {
  38. courseDataArray.push(_this.data[key]);
  39. });
  40. max = Math.max(...courseDataArray) + 20;
  41. // 基于准备好的dom,初始化echarts实例
  42. this.myChart = this.$echarts.init(document.getElementById(this.id));
  43. this.myChart.setOption({
  44. title:{
  45. text:'常用科技分布图',
  46. left: 'center',
  47. textStyle:{
  48. color: '#fafafa',
  49. fontWeight: 100,
  50. }
  51. },
  52. legend: {
  53. top: 20,
  54. textStyle: {
  55. color: '#fff',
  56. },
  57. data: ['总量', '英文', '语文', '英语', '数学', '科学', '综合']
  58. },
  59. backgroundColor: '#343a4073',
  60. tooltip: {
  61. trigger: 'axis',
  62. axisPointer: {
  63. type: 'shadow'
  64. },
  65. },
  66. grid: {
  67. left: '0',
  68. right: '0',
  69. bottom: '1px',
  70. top:'0',
  71. containLabel: true
  72. },
  73. xAxis: {
  74. type: 'category',
  75. boundaryGap: true,
  76. data: xLabel,
  77. axisLabel: {
  78. // inside: true,
  79. textStyle: {
  80. color:'#fafafa'
  81. }
  82. },
  83. axisLine: {
  84. show: true,
  85. lineStyle: {
  86. width: 1,
  87. color: 'rgba(185, 193, 173, 0.63)'
  88. }
  89. },
  90. splitLine: {
  91. show: true,
  92. lineStyle: {
  93. width: 1,
  94. color: 'rgba(185, 193, 173, 0.63)'
  95. }
  96. }
  97. },
  98. yAxis: {
  99. type: 'value',
  100. max: max,
  101. minInterval: 1,
  102. axisLabel: {
  103. inside: true,
  104. textStyle: {
  105. color:'transparent'
  106. }
  107. },
  108. axisLine: {
  109. show: true,
  110. lineStyle: {
  111. width: 1,
  112. color: 'rgba(185, 193, 173, 0.63)'
  113. }
  114. },
  115. splitLine: {
  116. show: true,
  117. lineStyle: {
  118. width: 1,
  119. color: 'rgba(185, 193, 173, 0.63)'
  120. }
  121. },
  122. },
  123. series: [
  124. {
  125. name:'总量',
  126. type: 'bar',
  127. data: courseDataArray,
  128. barWidth: 10, //柱子宽度
  129. // barGap: 1, //柱子之间间距
  130. itemStyle: {
  131. normal: {
  132. color: function(params) {
  133. var num=barcolor.length;
  134. return barcolor[params.seriesIndex%num]
  135. },
  136. }
  137. }
  138. },
  139. {
  140. name:'语文',
  141. type:'bar',
  142. barWidth: 10, //柱子宽度
  143. data:[30, 15, 14, 13, 12, 11, 10, 9, 3, 2, 2],
  144. itemStyle: {
  145. normal: {
  146. color: function(params) {
  147. var num=barcolor.length;
  148. return barcolor[params.seriesIndex%num]
  149. },
  150. }
  151. }
  152. },
  153. {
  154. name:'英语',
  155. type:'bar',
  156. barWidth: 10, //柱子宽度
  157. data:[30, 7, 14, 7, 6, 11, 10, 9, 3, 2, 2],
  158. itemStyle: {
  159. normal: {
  160. color: function(params) {
  161. var num=barcolor.length;
  162. return barcolor[params.seriesIndex%num]
  163. },
  164. }
  165. }
  166. },
  167. {
  168. name:'数学',
  169. type:'bar',
  170. barWidth: 10, //柱子宽度
  171. data:[30, 7, 0, 5, 4, 2, 6, 5, 3, 2, 2],
  172. itemStyle: {
  173. normal: {
  174. color: function(params) {
  175. var num=barcolor.length;
  176. return barcolor[params.seriesIndex%num]
  177. },
  178. }
  179. }
  180. },
  181. {
  182. name:'科学',
  183. type:'bar',
  184. barWidth: 10, //柱子宽度
  185. data:[10, 1, 0, 0, 2, 3, 5, 5, 3, 2, 2],
  186. itemStyle: {
  187. normal: {
  188. color: function(params) {
  189. var num=barcolor.length;
  190. return barcolor[params.seriesIndex%num]
  191. },
  192. }
  193. }
  194. },
  195. {
  196. name:'综合',
  197. type:'bar',
  198. barWidth: 10, //柱子宽度
  199. data:[0, 0, 0, 0, 1, 0, 3, 1, 3, 2, 2],
  200. itemStyle: {
  201. normal: {
  202. color: function(params) {
  203. var num=barcolor.length;
  204. return barcolor[params.seriesIndex%num]
  205. },
  206. }
  207. }
  208. },
  209. ]
  210. })
  211. }
  212. }
  213. }
  214. </script>
  215. <style>
  216. </style>