lineE.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <el-row >
  3. <div
  4. id="index2"
  5. style="height:300px;margin-top:-50px;"
  6. ></div>
  7. </el-row>
  8. </template>
  9. <script>
  10. import * as echarts from 'echarts';
  11. export default {
  12. props: ["resData"],
  13. data() {
  14. return {
  15. data:[]
  16. };
  17. },
  18. watch: {
  19. resData(val,old){
  20. this.data = val
  21. this.getData()
  22. }
  23. },
  24. methods: {
  25. getData() {
  26. let myChart = echarts.init(document.getElementById("index2"));
  27. let option = {
  28. tooltip: {
  29. trigger: 'axis',
  30. axisPointer: {
  31. type: 'shadow'
  32. }
  33. },
  34. grid: {
  35. left: '0%',
  36. right: '0%',
  37. bottom: '15%',
  38. containLabel: true
  39. },
  40. legend: {
  41. itemHeight: 6,
  42. itemWidth: 20,
  43. bottom: '4%',
  44. textStyle:{
  45. color:"#E6EFFF",
  46. }
  47. },
  48. xAxis: [
  49. {
  50. type: 'category',
  51. data: this.data[0],
  52. axisTick: {
  53. alignWithLabel: true
  54. },
  55. axisLabel: {
  56. color: "#B9C4D8",
  57. },
  58. axisLine: {
  59. lineStyle: {
  60. color: "rgba(160,180,234,0.2)",
  61. },
  62. },
  63. }
  64. ],
  65. yAxis: [
  66. {
  67. type: 'value',
  68. axisLabel: {
  69. color: "#B9C4D8",
  70. },
  71. // axisLine: {
  72. // lineStyle: {
  73. // color: "#B9C4D8",
  74. // },
  75. // },
  76. }
  77. ],
  78. series: [
  79. {
  80. name: "使用时长(小时)",
  81. type: 'bar',
  82. barWidth: '40%',
  83. itemStyle: {
  84. normal: {
  85. color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [{
  86. offset: 0,
  87. color: '#B99259'
  88. }, {
  89. offset: 1,
  90. color: '#E9CA7C'
  91. }]),
  92. }
  93. },
  94. data: this.data[1],
  95. },
  96. ]
  97. };
  98. myChart.setOption(option);
  99. option && myChart.setOption(option);
  100. setTimeout(function () {
  101. window.onresize = function () {
  102. myChart.resize();
  103. };
  104. }, 200);
  105. },
  106. },
  107. };
  108. </script>