conference.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <div class="person_box">
  3. <div ref="chartDistrict" style="width: 100%;height: 100%;"></div>
  4. </div>
  5. </template>
  6. <script setup>
  7. import * as echarts from 'echarts'
  8. defineProps({
  9. title: {
  10. type: String,
  11. default: '暂无数据'
  12. }
  13. })
  14. const chartDistrict = ref(null);
  15. let chartDom = null;
  16. const initAccess = () => {
  17. let MaxTemArray = [10, 3, 13, 11, 12, 12, 9];
  18. const dotColorsDic = ['blue', 'red']; // 点的颜色字典
  19. chartDom = echarts.init(chartDistrict.value);
  20. let option = {
  21. title: {
  22. text: '未来一周气温变化',
  23. subtarget: 'blank',
  24. x: 'center',
  25. top: '2%',
  26. textStyle: {
  27. fontSize: 15,
  28. color: "rgba(254, 254, 254, 1)"
  29. },
  30. },
  31. legend: {
  32. top: '2%',
  33. right: '0%',
  34. textStyle: {
  35. color: "rgba(254, 254, 254, 1)"
  36. },
  37. },
  38. grid: {
  39. top: '12%',
  40. bottom: '12%',
  41. left: '14%',
  42. right: '2%'
  43. },
  44. tooltip: {
  45. trigger: 'axis'
  46. },
  47. xAxis: {
  48. type: 'category',
  49. axisLine: {
  50. lineStyle: {
  51. color: '#C0C4CC',
  52. width: 2
  53. }
  54. },
  55. boundaryGap: false,
  56. data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
  57. },
  58. yAxis: {
  59. type: 'value',
  60. axisLabel: {
  61. formatter: '{value} °C'
  62. },
  63. axisLine: {
  64. lineStyle: {
  65. color: '#C0C4CC',
  66. width: 2
  67. }
  68. },
  69. },
  70. series: [{
  71. name: '最高气温',
  72. type: 'line',
  73. color: '#ff6b93', // 定义legend图例中线颜色
  74. symbol: "circle",
  75. lineStyle: {
  76. // 线的颜色
  77. color: "rgba(28, 193, 91, 1)",
  78. cap: "round"
  79. },
  80. itemStyle: {
  81. normal: {
  82. color: (params) => {
  83. if (params.data > 10) {
  84. return dotColorsDic[1]
  85. } else {
  86. return dotColorsDic[0]
  87. }
  88. }
  89. }
  90. },
  91. symbolSize: 6,
  92. label: {
  93. show: false
  94. },
  95. markLine: {
  96. data: [{
  97. type: 'average',
  98. name: '最高气温平均值',
  99. lineStyle: {
  100. color: '#0ED638'
  101. },
  102. label: {
  103. formatter: "{b}{c}°C",
  104. color: '#0ED638'
  105. }
  106. },
  107. {
  108. name: '阈值',
  109. yAxis: 12,
  110. lineStyle: {
  111. color: '#FF6464'
  112. },
  113. label: {
  114. formatter: "{b}{c}°C",
  115. color: '#FF6464'
  116. }
  117. }
  118. ]
  119. },
  120. data: MaxTemArray
  121. },]
  122. };
  123. chartDom.setOption(option)
  124. };
  125. // 生命周期
  126. onMounted(() => {
  127. initAccess()
  128. });
  129. // 窗口自适应
  130. window.addEventListener('resize', () => {
  131. chartDom?.resize();
  132. });
  133. </script>
  134. <style scoped lang="scss">
  135. .person_box {
  136. width: 100%;
  137. height: 100%;
  138. display: flex;
  139. align-items: center;
  140. }
  141. </style>