uniapp中echart实例

1,自定义仪表盘

在这里插入图片描述

797_1706772047

index.vue

import {
    useGaugeStore } from "@/stores/utils";
const {
    currentValueEndAngle, currentSplitNumber } = storeToRefs(
  useGaugeStore()
);
const gaugeStore = useGaugeStore();

const wenduGauge = ref<chartBaseOptionsType>({
   
  width: "400rpx",
  height: "400rpx",
  chartsId: "test",
  setOptions: {
   
    graphic: [
      
      {
   
        type: "text",
        left: 20,
        top: 184,
        scaleX: 1.4,
        scaleY: 1.4,
        style: {
   
          text: gaugeStore.minHeat + "°C",
          fill: "#007C84",
        },
      },
      {
   
        type: "text",
        left: 160,
        top: 184,
        scaleX: 1.4,
        scaleY: 1.4,
        style: {
   
          text: gaugeStore.maxHeat + "°C",
          fill: "#007C84",
        },
      },
    ],
    series: [],
  },
});


const setGaugeOption = () => {
   
  const dataArr = [
    {
   
      type: "gauge",
      radius: "90%",
      splitNumber: 1,
      axisLine: {
   
        show: true,
        lineStyle: {
   
          width: 1,
          opacity: 1,
          color: [[1, "#007C84"]],
        },
      },
      startAngle: gaugeStore.startAngle,
      endAngle: gaugeStore.endAngle,
      title: {
    show: false },
      detail: {
    show: false },
      splitLine: {
    show: false },
      axisTick: {
   
        length: 10,
        splitNumber: 60,
        lineStyle: {
   
          color: "rgba(0, 118, 135, 0.2)",
          width: 2,
        },
      },
      axisLabel: {
    show: false },
      pointer: {
    show: false },
      itemStyle: {
   },
    },
    {
   
      type: "gauge",
      radius: "90%",
      splitNumber: currentSplitNumber.value ? 1 : 0,
      axisLine: {
   
        show: false,
        lineStyle: {
   
          width: 0,
          opacity: 0,
        },
      },
      startAngle: gaugeStore.startAngle,
      endAngle: gaugeStore.getValueEndAngle(),
      title: {
    show: false },
      detail: {
   
        show: true,
        offsetCenter: [0, 0],
        color: "#00495F",
        fontSize: 34,
      },
      splitLine: {
    show: false },
      axisTick: {
   
        length: 11,
        splitNumber: currentSplitNumber.value,
        lineStyle: {
   
          color: "#23BAC4",
          width: 2,
        },
      },
      axisLabel: {
    show: false },
      pointer: {
    show: false },
      itemStyle: {
   },

      data: [{
    value: popUpValue.value.temperature }],
    },
  ];
  wenduGauge.value.setOptions.series = dataArr;
};

const handlerHeat = (type: string) => {
   
  popUpValue.value.temperature =
    type === "jia"
      ? popUpValue.value.temperature + 1
      : popUpValue.value.temperature - 1;

  open();
};
const open = () => {
   
  gaugeStore.setCurrentValue(popUpValue.value.temperature);
  setGaugeOption();
};

utils.ts文件

import {
    ref } from "vue";
import {
    defineStore } from "pinia";
export const useGaugeStore = defineStore("gauge", () => {
   
  const splitCount = 60; //刻度总数

  const startAngle = 225; // 开始角度

  const endAngle = -45; // 结束角度

  const totalAngle = 270; //总的角度

  const currentValueEndAngle = ref(0); //值现在的结束角度

  const currentSplitNumber = ref(0); //当前刻度数

  const maxHeat = 31;

  const minHeat = 16;

  const heatRange = maxHeat - minHeat;

  function setCurrentValue(currentHeat: number) {
   
    const a = totalAngle / splitCount;

    const b = (splitCount / heatRange) * (currentHeat - minHeat);
    console.log(a, b);

    currentSplitNumber.value = b;

    currentValueEndAngle.value = a * b;
    // 144 32
  }

  function getValueEndAngle() {
   
    return startAngle - currentValueEndAngle.value;
  }
  
  return {
   
    startAngle,
    endAngle,
    maxHeat,
    minHeat,
    currentValueEndAngle,
    currentSplitNumber,
    setCurrentValue,
    getValueEndAngle,
  };
});

相关推荐

  1. uniapp怎么引入echarts(最简单)

    2024-02-01 18:14:04       37 阅读
  2. uniapp echarts x轴 支持html标签

    2024-02-01 18:14:04       47 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-01 18:14:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-01 18:14:04       106 阅读
  3. 在Django里面运行非项目文件

    2024-02-01 18:14:04       87 阅读
  4. Python语言-面向对象

    2024-02-01 18:14:04       96 阅读

热门阅读

  1. 开源机器人ros 基本概念详细介绍

    2024-02-01 18:14:04       55 阅读
  2. 通过 React 来构建界面

    2024-02-01 18:14:04       51 阅读
  3. 白虎汤原方

    2024-02-01 18:14:04       59 阅读
  4. QTimer 指针类型和引用类型使用的区别

    2024-02-01 18:14:04       57 阅读
  5. 2024 高级前端面试题之 Node 「精选篇」

    2024-02-01 18:14:04       63 阅读
  6. c++if else 解释

    2024-02-01 18:14:04       50 阅读
  7. 基于低代码的管理系统模板库的设计与实现

    2024-02-01 18:14:04       56 阅读