Echarts表示进度的仪表盘

 1.所需图案样式

2.封装了一个组件可以直接用

*注:isBoard这个变量是用来控制图列的大小,项目中多次用到这个图列但大小不同

<template>
  <div class="content">
    <div ref="ringEchart" :class="{ mainBoard: props.isBoard, detailBoard: !props.isBoard }"></div>
  </div>
</template>

<script setup>
import { ref, onMounted, watch, defineProps } from "vue";
import * as echarts from "echarts";

// 定义接收的 props,fromParent 是接收父组件传递过来的属性
const props = defineProps({
  // 数值
  shiftOee: Number,
  isBoard: Boolean,
});
const ringEchart = ref(null);
function initChart() {
  const chart = echarts.init(ringEchart.value);
  const option = {
    title: {
      text: props.shiftOee,
      x: "center",
      y: "center",
      textStyle: {
        width: 21,
        height: 16,
        fontFamily: "Arial",
        fontWeight: "bold",
        // lineHeight: 133,
        color: "#fff",
        fontSize: props.isBoard ? 26 : 52,
      },
    },
    series: [
      {
        type: "pie",
        radius: ["100%", "70%"],
        silent: true,
        clockwise: true,
        startAngle: 90,
        z: 0,
        zlevel: 0,
        label: {
          position: "center",
        },
        data: [
          {
            value: props.shiftOee,
            // value
            name: "",
            itemStyle: {
              color: "#03A6E5",
            },
          },
          {
            value: props.shiftOee <= 100 ? 100 - props.shiftOee : 0,
            // 100 - value
            name: "",
            label: {
              show: false,
            },
            itemStyle: {
              color: "#2A4363",
            },
          },
        ],
      },
      {
        name: "分割线",
        type: "gauge",
        radius: props.isBoard ? "100%" : "128%", //配合splitLine里的length一起调
        clockwise: true,
        center: ["50%", "50%"],
        startAngle: "60",
        endAngle: "-299.9999",
        // startAngle: "0",
        // endAngle: "359.9",
        splitNumber: 24,
        // zlevel: 2,
        // detail: {
        //   offsetCenter: [10, 20],
        //   formatter: " ",
        // },
        axisLine: {
          lineStyle: {
            width: 0,
            opacity: 0,
          },
        },
        axisTick: {
          show: false,
        },
        markArea: {
          itemStyle: {
            color: "#0f0",
          },
        },
        splitLine: {
          show: true,
          length: 100, //配合radius一起调
          padding: [0, 0, 0],
          lineStyle: {
            color: "#121d43",
            width: 2.5,
          },
        },
        axisLabel: {
          show: false,
        },
      },
      {
        type: "pie",
        radius: "80%",
        center: ["50%", "50%"],
        silent: true,
        clockwise: true,
        startAngle: 90,
        z: 0,
        zlevel: 0,
        label: {
          position: "center",
        },
        data: [
          {
            value: 0,
            name: "",
            label: {
              show: false,
            },
            itemStyle: {
              color: "rgba(11,28,55)",
            },
          },
        ],
      },
    ],
  };
  chart.setOption(option);
}

watch(() => props.shiftOee, initChart);

onMounted(() => {
  //一定要在DOM渲染结束后,再去加载。因而延迟请求
  setTimeout(() => {
    initChart();
  }, 100);
});
</script>

<style scoped>
.mainBoard {
  width: 92px;
  height: 92px;
  margin-bottom: 8px;
  margin-top: 10px;
  margin-right: 10px;
}
.detailBoard {
  width: 130px;
  height: 130px;
  margin-bottom: 21px;
  /*fontSize:50px,*/
  /*margin-bottom: 8px;*/
}
</style>

3.运用

在所需页面引入组件


import statusEcharts from "./statusEcharts.vue";
<statusEcharts ref="echartsViews_rate" :isBoard="true" :shiftOee="100"></statusEcharts>

希望对你们有所帮助o(* ̄▽ ̄*)ブ

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值