EchartBar.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <script setup>
  2. import { ref, watch, onMounted, onUnmounted } from 'vue';
  3. import * as echarts from 'echarts';
  4. import { getBarOptions } from '../config/echartOption';
  5. let chart = null;
  6. const echartRef = ref(null);
  7. const props = defineProps({
  8. screenData: {
  9. type: Object,
  10. default: []
  11. }
  12. })
  13. watch(() => props.screenData, (currentVal) => {
  14. const { no3Hlj1Jqr, no3Hlj2Jqr, nh31Jqr, nh32Jqr, tpRccJqr } = currentVal;
  15. const options = [ no3Hlj1Jqr, no3Hlj2Jqr, nh31Jqr, nh32Jqr, tpRccJqr ].map(item => {
  16. return item ? Number(item.toFixed(2)) : 0;
  17. })
  18. chart.setOption( getBarOptions(options) )
  19. })
  20. const windowResize = () => {
  21. chart.resize();
  22. }
  23. onMounted(() => {
  24. chart = echarts.init(echartRef.value, 'light');
  25. window.addEventListener("resize", windowResize);
  26. })
  27. onUnmounted(() => {
  28. window.removeEventListener("resize", windowResize);
  29. })
  30. </script>
  31. <template>
  32. <div class="home-box echart-box">
  33. <div class="home-box-top">
  34. <div class="title">连续检测</div>
  35. </div>
  36. <div class="main">
  37. <ul class="legeng_inner space-x-[3rem]">
  38. <li class="item space-x-[0.6rem]">
  39. <span class="square-icon border-[#FF6737]"><i class="bg-[#FF6737]"></i></span>
  40. <span>当前值</span>
  41. </li>
  42. <li class="item space-x-[0.6rem]">
  43. <span class="square-icon border-[#00AB84]"><i class="bg-[#00AB84]"></i></span>
  44. <span>范围值</span>
  45. </li>
  46. </ul>
  47. <div class="echart_inner">
  48. <div class="echart w-full h-full" ref="echartRef"></div>
  49. </div>
  50. </div>
  51. </div>
  52. </template>
  53. <style lang="scss" scoped>
  54. .echart-box {
  55. min-height: 30rem;
  56. .echart_inner {
  57. height: calc(100% - 5.6rem);
  58. }
  59. }
  60. .main {
  61. height: 100%;
  62. padding: 1.8rem 1.8rem 1.6rem;
  63. .legeng_inner {
  64. display: flex;
  65. align-items: center;
  66. justify-content: flex-end;
  67. color: #415B73;
  68. .item {
  69. display: flex;
  70. align-items: center;
  71. justify-content: center;
  72. font-size: 1.2rem;
  73. .square-icon {
  74. display: inline-block;
  75. padding: 0.1rem;
  76. border-width: 0.2rem;
  77. border-style: solid;
  78. background: #fff;
  79. i {
  80. display: block;
  81. width: 0.8rem;
  82. height: 0.8rem;
  83. }
  84. }
  85. }
  86. }
  87. }
  88. </style>