oneLineChart.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <div ref="chartDom" class="charts"></div>
  3. </template>
  4. <script setup>
  5. import { onMounted, ref,watch } from "vue";
  6. import * as echarts from "echarts";
  7. import { oneLine } from "./options/oneLineOption";
  8. import { deepClone } from "@/common/commonFun";
  9. const props = defineProps({
  10. styleName: {
  11. type: String,
  12. default: "styleName1",
  13. },
  14. xData: {
  15. type: Array,
  16. default: () => [],
  17. },
  18. yData: {
  19. type: Array,
  20. default: () => [],
  21. },
  22. minData: {
  23. type: Array,
  24. default: () => [],
  25. },
  26. });
  27. const chartDom = ref(null);
  28. const myChart = ref(null);
  29. const options = ref(null);
  30. const initData = () =>{
  31. oneLine.series[0].data = props.yData
  32. oneLine.series[0].markPoint.data[0].value = props.yData[0] + '°'
  33. oneLine.series[0].markPoint.data[0].yAxis = props.yData[0]
  34. oneLine.series[0].markPoint.data[1].yAxis = props.yData[0]
  35. oneLine.series[1].data = props.minData
  36. oneLine.series[1].markPoint.data[0].value = props.minData[0] + '°'
  37. oneLine.series[1].markPoint.data[0].yAxis = props.minData[0]
  38. oneLine.series[1].markPoint.data[1].yAxis = props.minData[0]
  39. options.value = deepClone(oneLine);
  40. myChart.value.setOption(options.value);
  41. }
  42. onMounted(() => {
  43. myChart.value = echarts.init(chartDom.value);
  44. });
  45. watch(()=>props.yData,(newValue,oldValue) =>{
  46. if(newValue){
  47. initData();
  48. }
  49. })
  50. </script>
  51. <style lang="scss" scoped>
  52. .charts {
  53. width: 100%;
  54. height: 100%;
  55. }
  56. </style>