LineChart.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div :class="className" :style="{height:height,width:width}"/>
  3. </template>
  4. <script>
  5. import * as echarts from 'echarts'
  6. require('echarts/theme/macarons') // echarts theme
  7. import resize from '../mixins/resize'
  8. import {getLdpeLine} from "@/api/common/homedataCbpb";
  9. export default {
  10. mixins: [resize],
  11. props: {
  12. className: {
  13. type: String,
  14. default: 'chart'
  15. },
  16. width: {
  17. type: String,
  18. default: '100%'
  19. },
  20. height: {
  21. type: String,
  22. default: '350px'
  23. },
  24. autoResize: {
  25. type: Boolean,
  26. default: true
  27. },
  28. chartData: {
  29. type: Object,
  30. required: true
  31. }
  32. },
  33. data() {
  34. return {
  35. chart: null,
  36. nextEdit: [],
  37. nextReview: [],
  38. monthList: [],
  39. }
  40. },
  41. mounted() {
  42. this.$nextTick(() => {
  43. getLdpeLine().then(res => {
  44. for (const item of res.data.nextEdit) {
  45. this.monthList.push(item.dataMonth);
  46. this.nextEdit.push(item.dataCount);
  47. }
  48. for (const item of res.data.nextReview) {
  49. this.nextReview.push(item.dataCount);
  50. }
  51. this.initChart()
  52. })
  53. })
  54. },
  55. beforeDestroy() {
  56. if (!this.chart) {
  57. return
  58. }
  59. this.chart.dispose()
  60. this.chart = null
  61. },
  62. methods: {
  63. initChart() {
  64. this.chart = echarts.init(this.$el, 'macarons')
  65. this.chart.setOption(
  66. {
  67. xAxis: {
  68. data: this.monthList,
  69. axisTick: {
  70. show: false
  71. }
  72. },
  73. grid: {
  74. left: 10,
  75. right: 30,
  76. bottom: 40,
  77. top: 30,
  78. containLabel: true
  79. },
  80. tooltip: {
  81. trigger: 'axis',
  82. axisPointer: {
  83. type: 'shadow' // 修改为柱状图的显示方式
  84. },
  85. },
  86. yAxis: {
  87. axisTick: {
  88. show: false
  89. }
  90. },
  91. legend: {
  92. data: ['下次修订日期', '下次回顾日期']
  93. },
  94. series: [
  95. {
  96. name: '下次修订日期',
  97. type: 'bar', // 将类型修改为柱状图
  98. barWidth: '20%', // 设置柱状图的宽度
  99. itemStyle: {
  100. normal: {
  101. borderRadius: 15,
  102. }
  103. },
  104. data: this.nextEdit // 确保数据适用于柱状图
  105. },
  106. {
  107. name: '下次回顾日期',
  108. type: 'bar', // 将类型修改为柱状图
  109. barWidth: '20%', // 设置柱状图的宽度
  110. itemStyle: {
  111. normal: {
  112. borderRadius: 15,
  113. }
  114. },
  115. data: this.nextReview // 确保数据适用于柱状图
  116. }
  117. ]
  118. }
  119. )
  120. }
  121. }
  122. }
  123. </script>