echarts环形图自定义

echarts环形图自定义,光圈是图片自定义在终点

c 复制代码
  getCXQCharts(valNum, chartId, colorType) {
      const imgUrl =
        colorType === "red"
          ? require("@/assets/images/chrat_icon1.png")
          : require("@/assets/images/chrat_icon.png");
      this[chartId] = this.$echarts.init(document.getElementById(chartId));
      let color1 = colorType === "red" ? "#ae9600" : "#005fae";
      let color2 = colorType === "red" ? "#faa81b" : "#14c9fa";
      let color3 = colorType === "red" ? "#756b05" : "#053d75";

      let option = {
        title: {
          text: "{a|" + valNum + "}{b|%}",
          x: "center",
          y: "center",
          textStyle: {
            rich: {
              a: {
                fontSize: 44,
                fontWeight: "bold",
                color: "#fff",
                fontFamily: "DINPro",
              },
              b: {
                fontSize: 22,
                color: "#fff",
                fontFamily: "Source Han Sans CN",
              },
            },
          },
        },
        series: [
          {
            type: "pie",
            clockWise: false,
            radius: [57, 67], // 缩小饼图预留空间
            startAngle: 90,
            hoverAnimation: false,
            center: ["50%", "50%"],
            data: [
              {
                value: valNum,
                itemStyle: {
                  normal: {
                    color: new this.$echarts.graphic.LinearGradient(
                      0,
                      0,
                      0,
                      1,
                      [
                        { offset: 0, color: color1 },
                        { offset: 1, color: color2 },
                      ]
                    ),
                  },
                },
              },
              {
                //画中间的图标
                name: "",
                value: 0,
                offset: [-8, -18], // [-8向左偏移, -8向上偏移]
                label: {
                  position: "inside",
                  backgroundColor: {
                    image: imgUrl,
                  },
                  width: 28,
                  height: 28,
                
                },
              },
              {
                value: 100 - valNum,
                name: "invisible",
                itemStyle: {
                  normal: { color: color3 },
                  emphasis: { color: color3 },
                },
              },
            ],
          },
        ],
      };

      this[chartId].setOption(option, true);
    }
相关推荐
麻瓜生活睁不开眼4 小时前
Android16修改全局桌面视图边框四直角显示为弧边圆角
android·java·深度学习
东方小月6 小时前
从零开发一个 Coding Agent(四):使用状态机校验大模型事件流
前端·人工智能·后端
Csvn6 小时前
🧩 ESM vs CJS 混用的 7 个「天坑」——从 TypeScript 编译到 Node 与浏览器
前端
Csvn7 小时前
🎯 Web 性能 API 集合:Performance Observer 的 5 个冷门妙用
前端
Csvn7 小时前
深入 React 闭包陷阱:从根源上理解并根治 stale closure
前端
whyfail7 小时前
前端学 Spring Boot(8):接口为什么越用越慢?
前端·spring boot·后端
AFinalStone8 小时前
Android 7系统休眠唤醒(六)唤醒全链路
android·电源管理·休眠唤醒
用户059540174468 小时前
LangChain 记忆测试踩坑实录:这两个坑让我排查了 4 小时
前端·css
程序员黑豆8 小时前
鸿蒙应用开发:@Monitor 装饰器使用教程
前端·harmonyos
SamChan908 小时前
在Web应用中集成PDF多语言翻译功能:PDFTranslator API实战指南
前端·python·ai·pdf·yapi·机器翻译