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);
    }
相关推荐
红尘散仙14 小时前
谁说终端只能敲键盘?我用 Rust 给小说阅读器加上了鼠标
前端·后端·rust
陈随易15 小时前
C++26 草案被否,二十八年来头一回
前端·后端·程序员
ZhengEnCi15 小时前
Agent 工具怎么折叠海量输出才「爽」:Trae、Claude Code 的渐进式披露设计原理
前端·agent
IT_陈寒19 小时前
Redis内存暴涨,没想到是AOF重写捣的鬼
前端·人工智能·后端
ikoala19 小时前
让 Codex 自己查账:一个省 token 的小技巧
前端·后端·ai编程
ikoala19 小时前
AI 写页面像说明书,修 Bug 像贴膏药?把这两句话写进 AGENTS.md
前端·javascript·ai编程
好的佩奇20 小时前
Dart 之扩展方法
android·flutter·dart
去伪存真21 小时前
AI Agent Harness 深度测评与技术选型实战
前端·agent
三少爷的鞋21 小时前
换个思路理解:非阻塞挂起
android
好的佩奇1 天前
蓝牙之经典蓝牙
android·flutter·蓝牙