<template>
  <div class="container" ref="humiture">
  </div>
</template>
  
<script setup lang='ts'>
import { getCurrentInstance, markRaw, onMounted, reactive, ref, watch } from "vue";
const { proxy } = getCurrentInstance() as any;
const props = defineProps<{
  title: String;
  value: any;
}>();
let humiture = ref();
let chart = null
watch(props, (newVal) => {
  init()
}, { deep: true, })
function init() {

  const chart = proxy.$echarts.init(humiture.value, 'dark');
  let option = {
    title: {
      text: props.title,
      show: true,
      textStyle: {
        color: "#fff",
        fontSize: 20,
      },
      top: 5
    },
    grid: {
      // 让图表占满容器
      top: "0px",
      left: "0px",
      right: "0px",
      bottom: "0px",
    },
    series: [
      {
        type: "gauge",
        center: ["50%", "85%"],
        startAngle: 190,
        endAngle: -10,
        radius: "50%",
        min: -30,
        max: 70,
        splitNumber: 10,
        progress: {
          show: false,
          width: 5
        },
        pointer: {
          itemStyle: {
            color: 'inherit'
          }
        },
        //刻度轴宽
        axisLine: {
          lineStyle: {
            width: 10,
            color: [
              [0.15, '#FF6E76'],
              [0.75, '#7CFFB2'],
              [1, '#FF6E76']
            ]
          }
        },
        //刻度线
        axisTick: {
          show: false,
          distance: -5,
          splitNumber: 5,
          lineStyle: {
            width: 2,
            color: '#999'
          }
        },
        //刻度线
        splitLine: {
          distance: 5,
          length: 3,
          lineStyle: {
            width: 3,
            color: '#999'
          }
        },
        //表刻度值
        axisLabel: {
          distance: 15,
          color: '#999',
          fontSize: 10
        },
        anchor: {
          show: false
        },
        title: {
          show: false
        },
        detail: {
          valueAnimation: true,
          // width: '10%',
          // lineHeight: 5,
          // borderRadius: 8,
          offsetCenter: [0, '25%'],
          fontSize: 15,
          // fontWeight: 'bolder',
          formatter: '{value} °C',
          color: 'inherit'
        },
        data: [
          {
            value: props.value.c
          }
        ]
      },
      {
        type: "gauge",
        center: ["50%", "50%"],
        startAngle: 200,
        endAngle: -20,
        min: 0,
        max: 100,
        progress: {
          show: false,
          width: 5
        },
        pointer: {
          itemStyle: {
            color: 'inherit'
          }
        },
        //刻度轴宽
        axisLine: {
          lineStyle: {
            width: 10,
            color: [
              [0.15, '#FF6E76'],
              [0.75, '#7CFFB2'],
              [1, '#FF6E76']
            ]
          }
        },
        //刻度线
        axisTick: {
          distance: 0,
          splitNumber: 5,
          lineStyle: {
            width: 2,
            color: '#999'
          }
        },
        //刻度线
        splitLine: {
          distance: 5,
          length: 3,
          lineStyle: {
            width: 3,
            color: '#999'
          }
        },
        axisLabel: {
          distance: 15,
          color: '#999',
          fontSize: 12
        },
        anchor: {
          show: false
        },
        title: {
          show: false
        },
        detail: {
          valueAnimation: true,
          offsetCenter: [0, '15%'],
          fontSize: 20,
          formatter: '{value} %RH',
          color: 'inherit'
        },
        data: [
          {
            value: props.value.h
          }
        ]
      },
    ],
  };

  chart.setOption(option);
}

onMounted(() => {
  init();
});
</script>
  
<style scoped>
.container {
  width: 100%;
  height: 100%;
}
</style>
  