饼图特定指示线和文字展示以及部分不展示

<template>
  <div class="content">
    <div
      ref="charts"
      style="width: 1200px; height: 1000px; margin: 0 auto"
    ></div>
  </div>
</template>
  
  <script>
import * as echarts from "echarts";
export default {
  data() {
    return {
      points: [],
    };
  },
  mounted() {
    this.initCharts();
  },
  methods: {
    initCharts() {
      const charts = echarts.init(this.$refs["charts"]);
      let arr = [
        {
          value: 335,
          legendname: "种类01",
          name: "种类01  335",
          itemStyle: {
            color: "#8d7fec",
          },
        },
        {
          value: 310,
          legendname: "种类02",
          name: "种类02  310",
          itemStyle: {
            color: "#5085f2",
          },
        },
        {
          value: 234,
          legendname: "种类03",
          name: "种类03  234",
          itemStyle: {
            color: "#e75fc3",
          },
        },
        {
          value: 154,
          legendname: "种类04",
          name: "种类04  154",
          itemStyle: {
            color: "#f87be2",
          },
        },
        {
          value: 335,
          legendname: "种类05",
          name: "种类05  335",
          itemStyle: { color: "#f2719a" },
        },
        {
          value: 335,
          legendname: "种类06",
          name: "种类06  335",
          itemStyle: { color: "#fca4bb" },
        },
        {
          value: 335,
          legendname: "种类07",
          name: "种类07  335",
          itemStyle: { color: "#f59a8f" },
        },
      ];
      arr = arr.map((item) => {
        return {
          ...item,
          emphasis: {
            labelLine: {
              show: true,
            },
          },
          label: {
            normal: {
              show: (function () {
                if (
                  item.legendname == "种类01" ||
                  item.legendname == "种类02"
                  || item.legendname == "种类03"
                  || item.legendname == "种类04"
                  || item.legendname == "种类05"
                  || item.legendname == "种类06"
                ) {
                  return false;
                } else {
                  return true;
                }
              })(),
              formatter: (params) => {
                return params.percent + "|" + params.value;
              },
              borderWidth: 0,
              borderRadius: 4,
              padding: [0, -86],
              height: 70,
              fontSize: 13,
              align: "center",
              color: "#ffffff",
              rich: {
                b: {
                  fontSize: 12,
                  lineHeight: 20,
                  color: "#ffffff",
                  padding: [0, 0, 5, 0],
                },
                c: {
                  fontSize: 20,
                  lineHeight: 20,
                  color: "#ffffff",
                },
              },
            },
          },
          labelLine: {
            show: (function () {
              if (item.legendname == "种类01" || item.legendname == "种类02") {
                return false;
              } else {
                return true;
              }
            })(),
            lineStyle: {
              color: "#ffffff", // 改变标示线的颜色
            },
          },
        };
      });
      let option1 = {
        backgroundColor: "#05274C",
        grid: {
          left: "20%",
        },
        color: [
          "#2AC9FD",
          "#76FBC0",
          "#35C96E",
          "#FCC708",
          "#48B188",
          "#5957C2",
          "#4A5D73",
        ],
        tooltip: {
        trigger: 'item',
        formatter:function (parms){
          var str=  parms.seriesName+"</br>"+
            parms.marker+""+parms.data.legendname+"</br>"+
            "数量:"+ parms.data.value+"</br>"+
            "占比:"+ parms.percent+"%";
            return  str ;
        }
    },
    legend: {
        type:"scroll",
        orient: 'vertical',
        left:'80%',
        align:'left',
        top:'middle',
        textStyle: {
            color:'#8C8C8C'
        },
        height:250
    },
        series: [
          {
            color: [
              "#2AC9FD",
              "#76FBC0",
              "#35C96E",
              "#FCC708",
              "#48B188",
              "#5957C2",
            ],
            type: "pie",
            radius: "50%",
            labelLine: {
              normal: {
                length: 25,
                length2: 120,
                lineStyle: {
                  type: "solid",
                },
              },
            },
            data: [...arr],
          },
        ],
      };
      charts.setOption(option1);
    },
  },
};
</script>
  <style scoped>
.content {
  background-color: #0e2152;
  height: 100%;
}
</style>
  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值