常见的Eachers仪表盘

// 仪表盘
<template>
  <div>
    <div style="width:21vw;height:20vw" ref="gauge"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";

export default {
  props: {
    value: {
      default: 0,
    },
    titleText: {},
  },

  data() {
    return {};
  },
  mounted() {
    var myChart = echarts.init(this.$refs.gauge);
    let option = {
      title: {
        //配置标题组件
        text: this.titleText || "",
        x: "center",
        y: "88%",
        show: true, //设置是否显示标题,默认true
        //设置相对于仪表盘中心的偏移位置
        //数组第一项是水平方向的偏移,第二项是垂直方向的偏移
        offsetCenter: [50, "100%"],
        textStyle: {
          fontFamily: "黑体", //设置字体名称,默认宋体
          color: "black", //设置字体颜色,默认#333
          fontSize: 20, //设置字体大小,默认15
        },
      },
      series: [
        {
          type: "gauge",
          splitNumber: 8,
          axisLine: {
            lineStyle: {
              width: 15,
              color: [
                [0.25, "#FF0000"],
                [0.75, "#FFD700"],
                [1, "#1E90FF"],
              ],
            },
          },
          pointer: {
            //指针
            itemStyle: {
              color: "#778899",
            },
            icon: "triangle",
            length: "70%", // 指针长度,可以是绝对数值,也可以是相对于半径的百分比,默认 80%。
            width: 10, // 指针宽度,默认 8。
          },
          axisTick: {
            //刻度线
            show: false,
            // distance: -30,
            // length: 2,
            // lineStyle: {
            //   color: "#fff",
            //   width: 1,
            // },
          },
          splitLine: {
            distance: -30,
            length: 15,
            lineStyle: {
              color: "#fff",
              width: 2,
            },
          },
          axisLabel: {
            //'仪表盘数字刻度'
            color: "#CCCCCC",
            distance: 12,
            fontSize: 10,
          },
          detail: {
            //设置仪表盘详情,用于显示数据
            valueAnimation: true,
            fontSize: 30,
            offsetCenter: [0, "80%"], //设置相对于仪表盘中心的偏移位置
            formatter: "{value} %",
            color: "black",
            formatter: function(value) {
              //圆心处 描述文字 格式
              return value + "%\n" + "\n" + "{unit|1,000,000}";
            },
            rich: {
              value: {
                fontSize: 50,
                fontWeight: "bolder",
                color: "#777",
              },
              unit: {
                fontSize: 20,
                color: "#ff0000",
                padding: [0, 0, -20, 10],
              },
            },
          },

          data: [
            {
              name: "完成率",
              value: this.value || 0,
              itemStyle: { color: "#778899" }, //指针颜色
            },
          ],
        },
      ],
    };
    // setInterval(function() {
    //   myChart.setOption({
    //     series: [
    //       {
    //         data: [
    //           {
    //             value: +(Math.random() * 100).toFixed(2),
    //           },
    //         ],
    //       },
    //     ],
    //   });
    // }, 2000);

    option && myChart.setOption(option);
  },
};
</script>

<style></style>

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值