小程序中使用echarts实现带边框雷达图

小程序中怎么使用echarts的流程在这边文章,点击去观看

我们项目需要实现一个带边框的雷达图,看了API之后没有发现怎么去实现这个边框,所以想到了画两个雷达图来实现这个边框,具体效果如上,代码如下

cpp 复制代码
  // 初始化雷达图
  init() {
    let { optionsValue } = this.data;
    function bar(canvas, width, height, dpr) {
      const chart = echarts.init(canvas, null, {
        width: width,
        height: height,
        devicePixelRatio: dpr,
      });
      canvas.setChart(chart);
      let option = {
        title: {
          text: "自定义雷达图",
        },

        radar: [
          {
            indicator: [
              { text: "信任", max: 5 },
              { text: "冲突", max: 5 },
              { text: "承诺", max: 5 },
              { text: "责任", max: 5 },
              { text: "结果", max: 5 },
            ],
            center: ["50%", "50%"],
            radius: 110,
            startAngle: 90,
            splitNumber: 4,
            shape: "circle",
            name: {
              formatter: "{value}",
              textStyle: {
                color: "#333333",
              },
            },
            // 设置区域边框和区域的颜色
            itemStyle: {
              normal: {
                color: "#FF92AC",
                lineStyle: {
                  color: "#FF92AC",
                },
              },
            },
            splitArea: {
              areaStyle: {
                color: "#fff",
                shadowColor: "rgba(0, 0, 0, 0.3)",
                // shadowBlur: 10,
              },
            },
            axisLine: {
              lineStyle: {
                color: "#E9E9E9",
                type: "dashed",
              },
            },
            splitLine: {
              lineStyle: {
                color: "#E9E9E9",
                type: "dashed",
              },
            },
          },
          {
            indicator: [
              {
                max: 100,
              },
              {
                max: 100,
              },
              {
                max: 100,
              },
              {
                max: 100,
              },
              {
                max: 100,
              },
            ],

            center: ["50%", "50%"],
            radius: 111,
            startAngle: 90,
            splitNumber: 1,
            shape: "circle",
            splitArea: {
              show: false,
            },
            axisLine: {
              show: false,
            },
            splitLine: {
              lineStyle: {
                color: "#FF92AC",
                type: "solid",
                width: 2,
              },
            },
          },
        ],
        series: [
          {
            name: "雷达图",
            type: "radar",
            silent: false,
            emphasis: {
              lineStyle: {
                width: 4,
              },
            },

            symbolSize: 0,

            data: [
              {
                value: optionsValue,
                name: "图一",
                symbol: "rect",
                areaStyle: {
                  color: "#FF92AC",
                },
                itemStyle: {
                  normal: {
                    color: "#FF92AC",
                    lineStyle: {
                      color: "#FF92AC",
                    },
                  },
                },
              },
            ],
          },
        ],
      };
      chart.setOption(option);
      return chart;
    }
    let str = "ec.onInit.br";
    let ec = { onInit: bar };
    this.setData({
      ec,
    });
  },

通过第二个雷达图跟第一个雷达图同心圆,半径比实际展示的大一点,splitNumber:1来实现一个只有外边框的雷达图

相关推荐
Mr.Jessy14 分钟前
JavaScript高级:构造函数与原型
开发语言·前端·javascript·学习·ecmascript
白兰地空瓶2 小时前
🚀你以为你在写 React?其实你在“搭一套前端操作系统”
前端·react.js
爱上妖精的尾巴3 小时前
6-4 WPS JS宏 不重复随机取值应用
开发语言·前端·javascript
似水流年QC3 小时前
深入探索 WebHID:Web 标准下的硬件交互实现
前端·交互·webhid
陪我去看海3 小时前
测试 mcp
前端
speedoooo4 小时前
在现有App里嵌入一个AI协作者
前端·ui·小程序·前端框架·web app
全栈胖叔叔-瓜州4 小时前
关于llamasharp 大模型多轮对话,模型对话无法终止,或者输出角色标识User:,或者System等角色标识问题。
前端·人工智能
三七吃山漆4 小时前
攻防世界——wife_wife
前端·javascript·web安全·网络安全·ctf
用户47949283569154 小时前
面试官问"try-catch影响性能吗",我用数据打脸
前端·javascript·面试
GISer_Jing5 小时前
前端营销技术实战:数据+AI实战指南
前端·javascript·人工智能