classResourceBar.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. todayData:{
  16. type: Object,
  17. default: function(){
  18. return {'一年級': 9, '二年級': 11, '三年級': 16, '四年級':6, '五年級':13, '六年級':22}
  19. }
  20. },
  21. callBack: {
  22. type: String
  23. }
  24. },
  25. mounted(){
  26. this.drawLine();
  27. },
  28. methods:{
  29. drawLine(){
  30. let _this = this
  31. // 取得Y軸Label
  32. let yLabel = Object.keys(this.todayData);
  33. let todayDataArray = [];
  34. // 今日資料
  35. yLabel.map(function(key) {
  36. todayDataArray.push(_this.todayData[key]);
  37. });
  38. // 基于准备好的dom,初始化echarts实例
  39. this.myChart = this.$echarts.init(document.getElementById(this.id));
  40. this.myChart.setOption({
  41. backgroundColor: '#343a4073',
  42. tooltip: {
  43. trigger: 'axis',
  44. axisPointer: {
  45. type: 'shadow'
  46. },
  47. // formatter: function(params){
  48. // // 故意開啟 但不設定使ToolTip 沒有彈跳的作用 但有Hover 功能
  49. // }
  50. },
  51. grid: {
  52. left: '5%',
  53. right: '0',
  54. bottom: '0',
  55. top:'0',
  56. containLabel: true
  57. },
  58. xAxis: {
  59. type: 'value',
  60. boundaryGap: false,
  61. axisLabel: {
  62. inside: true,
  63. textStyle: {
  64. color:'transparent'
  65. }
  66. },
  67. splitLine: {
  68. show: true,
  69. lineStyle: {
  70. color: 'rgba(185, 193, 173, 0.63)'
  71. }
  72. }
  73. },
  74. yAxis: {
  75. type: 'category',
  76. axisLabel: {
  77. textStyle: {
  78. fontSize: 12,
  79. color: '#94998a'
  80. }
  81. },
  82. splitLine: {
  83. lineStyle: {
  84. color: 'rgba(185, 193, 173, 0.63)',
  85. },
  86. show: true
  87. },
  88. axisLine: {
  89. lineStyle: {
  90. color: 'rgba(185, 193, 173, 0.63)',
  91. width: 1,
  92. }
  93. },
  94. data: yLabel,
  95. },
  96. series: [
  97. {
  98. name: 'today',
  99. type: 'bar',
  100. data: todayDataArray,
  101. barWidth: 15, //柱子宽度
  102. itemStyle: {
  103. normal: { //渐变色
  104. color: new this.$echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  105. offset: 0,
  106. color: "rgba(228, 233, 220, 1)" // 0% 处的颜色
  107. },{
  108. offset: 1,
  109. color: "rgba(228, 233, 220, 0.5)" // 100% 处的颜色
  110. }], false)
  111. }
  112. }
  113. },
  114. ]
  115. })
  116. }
  117. }
  118. }
  119. </script>
  120. <style>
  121. </style>