highcharts-t.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <div style="height: 100%;">
  3. <Chart v-if="chartOptions1.series.length != 0" style="min-height: 600px;" :options="chartOptions1"
  4. constructor-type="stockChart">
  5. </Chart>
  6. <div style="text-align: center;margin-top: 20px;">{{ computedData }}</div>
  7. </div>
  8. </template>
  9. <script setup>
  10. import emitter from "@/plugin/bus";
  11. // const emit = defineEmits(['submit']);
  12. import { Chart } from 'highcharts-vue';
  13. import { computed, onBeforeUnmount, reactive, watch, ref ,nextTick} from "vue";
  14. import { useMessage } from "naive-ui";
  15. import { useStore } from 'vuex'
  16. const message = useMessage()
  17. const popData = defineProps({
  18. dataList: {
  19. type: Array,
  20. default: () => [],
  21. }
  22. })
  23. const plotLinesData = reactive({
  24. tBottom: null,
  25. tTop: null
  26. })
  27. const store = useStore()
  28. const plot = computed(() => store.state.plotLineList)
  29. nextTick(()=>{
  30. chartOptions1.yAxis.plotLines[0].value = plot.value.tTop
  31. chartOptions1.yAxis.plotLines[0].label.text = `上限(${plot.value.tTop}Rh)`, //标签的内容
  32. chartOptions1.yAxis.plotLines[1].value = plot.value.tBottom
  33. chartOptions1.yAxis.plotLines[1].label.text = `下限(${plot.value.tBottom}Rh)` //标签的内容
  34. })
  35. //设置就展示
  36. emitter.on("onMessage", (val) => {
  37. console.log('123',val)
  38. chartOptions1.yAxis.plotLines[0].value = val.tTop
  39. chartOptions1.yAxis.plotLines[0].label.text = `上限(${val.tTop}Rh)`, //标签的内容
  40. chartOptions1.yAxis.plotLines[1].value = val.tBottom
  41. chartOptions1.yAxis.plotLines[1].label.text = `下限(${val.tBottom}Rh)` //标签的内容
  42. });
  43. //关闭
  44. onBeforeUnmount(() => {
  45. emitter.off("onMessage");
  46. });
  47. const computedData = computed(() => {
  48. // console.log('计算属性',popData.dataList)
  49. if (popData.dataList.length != 0) {
  50. return computedDataFun()
  51. } else {
  52. return ''
  53. }
  54. })
  55. const computedDataFun = () => {
  56. let arr = popData.dataList
  57. let mapData = []
  58. for (const key of arr) {
  59. for (let i = 0; i < key.data.length; i++) {
  60. mapData.push(key.data[i][1])
  61. }
  62. }
  63. if (mapData.length == 0) {
  64. message.error('哎呀,没有可展示的数据哦')
  65. return
  66. }
  67. //求和
  68. let num = mapData.reduce((n, m) => n + m);//求和
  69. //最大值
  70. let maxData = Math.max(...mapData)
  71. //最小值
  72. let minData = Math.min(...mapData)
  73. //平均值
  74. let pingjun = (num / mapData.length).toFixed(1)
  75. return `最大值${maxData},最小值${minData},平均值${pingjun}`
  76. }
  77. watch(() => popData.dataList, (newValue) => {
  78. chartOptions1.series = []
  79. nextTick(()=>{
  80. chartOptions1.series = newValue
  81. })
  82. }, { deep: true, immediate: false })
  83. const emit = defineEmits(['setTimeFun']);
  84. // 图表配置
  85. const chartOptions1 = reactive({
  86. xAxis: {
  87. type: 'datetime',
  88. labels: {
  89. format: '{value:%Y-%m-%d %H:%M:%S}',
  90. },
  91. },
  92. time: {
  93. useUTC: false
  94. },
  95. boost: {
  96. useGPUTranslations: true
  97. },
  98. tooltip: {
  99. xDateFormat: '%Y-%m-%d %H:%M:%S',
  100. },
  101. yAxis: {
  102. opposite: false, //设置y轴提示在左边
  103. title: {
  104. // text: '温度℃'
  105. },
  106. plotLines: [{
  107. color: '#FF1D00', //线的颜色,定义为红色
  108. dashStyle: 'DashDot', //默认值,这里定义为实线
  109. value: plotLinesData.hTop, //定义在那个值上显示标示线,这里是在x轴上刻度为3的值处垂直化一条线
  110. width: 2, //标示线的宽度,2px
  111. label: {
  112. text: `上限(${plotLinesData.hTop}Rh)`, //标签的内容
  113. align: 'right', //标签的水平位置,水平居左,默认是水平居中center
  114. // x: 10 //标签相对于被定位的位置水平偏移的像素,重新定位,水平居左10px
  115. }
  116. }, {
  117. color: '#FF1D00', //线的颜色,定义为红色
  118. dashStyle: 'DashDot', //默认值,这里定义为实线
  119. value: plotLinesData.hBottom, //定义在那个值上显示标示线,这里是在x轴上刻度为3的值处垂直化一条线
  120. width: 2, //标示线的宽度,2px
  121. label: {
  122. text: `下限(${plotLinesData.hBottom}Rh)`, //标签的内容
  123. align: 'right', //标签的水平位置,水平居左,默认是水平居中center
  124. // x: 10 //标签相对于被定位的位置水平偏移的像素,重新定位,水平居左10px
  125. }
  126. }]
  127. },
  128. plotOptions: {
  129. series: {
  130. turboThreshold: 0 //性能阈值检查,默认值为1000,当数据量超过这个值就会报错;如果需要关掉性能阈值检查,可以将此参数设置为 0
  131. },
  132. },
  133. legend: {
  134. enabled: true,
  135. },
  136. accessibility: {
  137. enabled: false,
  138. },
  139. rangeSelector: {
  140. buttons: [], // 不显示左边的zoom
  141. selected: 1,
  142. inputEnabled: false // 不显示日期输入框
  143. },
  144. boost: {
  145. useGPUTranslations: true,
  146. seriesThreshold: 5,
  147. },
  148. scrollbar: {
  149. enabled: false,
  150. },
  151. chart: {
  152. zooming: {
  153. singleTouch: true,
  154. resetButton: {},
  155. type: 'xy',
  156. },
  157. events: {
  158. selection(event) {
  159. if (event.xAxis) {
  160. console.log('框选')
  161. emitter.emit("onSelectionTime",event.xAxis);
  162. emit("setTimeFun", event.xAxis)
  163. }
  164. },
  165. },
  166. },
  167. series: [],
  168. })
  169. </script>