echarts 环形图,饼图,中间文字设置,数据块文字设置,图例的设置 , 饼图中间白条添加,饼图边框添加

1. 如下图所示:

 

 

 2. 环形图代码如下 

          vue引入echarts:https://blog.csdn.net/qq_34790644/article/details/119932743

     1. 中间字设置是 title ,数据内部显示文字是series中的label,图例是legend

     var sxechart=this.$echart.init(document.getElementById('echartId'))   

     var data = [
        {
          name: "正常兼职",
          value: 456
        },
        {
          name: "即将超期",
          value: 231
        },
        {
          name: "超期",
          value: 71
        }
      ];

      var subText = ((456 / (456 + 231 + 71)) * 100).toFixed(0) + "%";

      var option = {
        //环形图中间文字
        title: {
          text: "正常兼职",
          subtext: subText,
          textStyle: {
            fontSize: 12,
            color: "rgba(0,0,0,0.65)",
            fontWeight: 400
          },
          subtextStyle: {
            fontSize: 20,
            color: "#000000",
            fontWeight: 500
          },
          textAlign: "center", //图例文字居中显示
          x: "38%",   //距离左边的距离
          y: "37%"    //距离上边的距离
        },
        //数据的颜色设置
        color: ["#2BCB95", "#F6BD16", "#FF3B30"],
        //鼠标移入显示的文字
        tooltip: {
          trigger: "item",
          formatter: "{b}<br/> {c}人  ({d}%)"
        },
        //图例设置
        legend: {
          orient: "vertical",  //竖直展示,如果横着的话,这个可以直接去掉
          right: "10%",
          top: "center",
          align: "left",
          itemGap: 20,  //数据上下的距离
          icon: "circle", //圆形小点展示,默认为方形,去掉就是方形展示
          itemWidth: 10, // 设置宽度
          data: data
        },
        series: [
          {
            radius: ["50%", "80%"], //第一个是中间圆的大小,第二个是外边圆的大小
            center: ["40%", "50%"], //左边的距离,上边的距离
            type: "pie",
            label: {、
              normal: {
                formatter: function(data) {
                  //.toFixed(0)去掉小数位,如果为2就是保留两位小数
                  let b = data.percent.toFixed(0) + "%";
                  subText = b;
                  return b;
                },
                // formatter: "{d}" + "%", //直接百分比,没有去掉小数位,上边是去掉小数位的
                //formatter: "{b}:{c}人"  //正常兼职:456 
                position: "inner", //文字显示在内部,如果在外边把这个去掉就好
                color: "#fff",     //文字的颜色
              }
            },
            data: data
          }
        ]
      };

      sxechart.setOption(option,true);

 2. 饼图的代码如下:

   

 var sxechart=this.$echart.init(document.getElementById('echartId')) 

 var option = {
        //鼠标移入显示文字
        tooltip: {
          trigger: "item",
          formatter: "{a}:{b}:({d}%)"
        },
        //图例设置
        legend: {
          orient: "vertical",
          left: "50%",
          top: "center",
          align: "left",
          itemGap: 20,
          icon: "circle",
          itemWidth: 10, // 设置宽度
          data: ["单位党委(党组,工委)审批", "区委组织部审批", "市委组织部审批"]
        },
        //颜色设置
        color: ["#5B8FF9", "#5AD8A6", "#78D3F8"],
        series: [
          {
            name: "访问来源",
            type: "pie",
            selectedMode: "single",
            radius: [0, "73%"], //饼图大小设置
            center: ["25%", "48%"], // 距离左边,距离上边距离
            //数据文字内部展示
            label: {
              normal: {
                formatter: "{d}%",
                position: "inner",
                color: "#fff"
              }
            },
            //中间的白边设置
            itemStyle: {
              // 此配置
              normal: {
                borderWidth: 1,
                borderColor: "#fff"
              },
            },
            data: [
              {
                value: 38.3,
                name: "单位党委(党组,工委)审批"
              },
              {
                value: 41.6,
                name: "区委组织部审批"
              },
              {
                value: 40.1,
                name: "市委组织部审批"
              }
            ]
          }
        ]
      };

     sxechart.setOption(option,true);

3. 不要忘了给echarts设置宽高哦!!!

  • 15
    点赞
  • 72
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wu_223

嘿嘿,求打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值