环形echarts图 颜色渐变 文字居中

本文介绍了如何在Vue项目中使用Echarts创建环形图,并实现颜色渐变效果。同时,详细讲解了如何设置使得图表内的文字保持居中显示,为视觉呈现提供更佳的用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述

      <div class="risk-type-echarts" id="main"></div>

import * as echarts from "echarts";
option: {
        title: {
          text: "14",
          x: "center",
          y: "center",
          top: "80",
          textStyle: {
            fontSize: 25,
            color: "#FAB208",
            fontWeight: "700",
          },
        },
        tooltip: {
          trigger: "item",
        },
        legend: {
          top: "0",
          left: "0",
          data: [],
        },
        graphic: {
          type: "text",
          left: "center",
          top: "120px",
          z: 2,
          zlevel: 100,
          style: {
            text: "巡检总次数",
            fill: "#fff",
            fontSize: 16,
          },
        },
        series: [
          {
            name: "",
            type: "pie",
            radius: ["60%", "90%"],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: "center",
            },
            emphasis: {
              label: {
                show: false,
                fontSize: "0",
                fontWeight: "bold",
              },
            },
            labelLine: {
              show: false,
            },
            data: [
              {
                value: 9,
                name: "累计巡检次数",
                itemStyle: {
                  normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                      { offset: 0, color: "#e6c24e" },
                      //   { offset: 0.5, color: "#FAFF75" },
                      { offset: 1, color: "#d87e42" },
                    ]),
                  },
                },
              },
              {
                value: 5,
                name: "累计漏检次数",
                itemStyle: {
                  normal: {
                    fontSize: 0,
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                      { offset: 0, color: "#48bbeb" },
                      //   { offset: 0.5, color: "#FAFF75" },
                      { offset: 1, color: "#3458e4" },
                    ]),
                  },
                },
              },
            ],
          },
        ],
      },

mounted() {
    // 基于准备好的dom,初始化echarts实例
    var myChart = echarts.init(document.getElementById("main"));

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(this.option);
  },
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值