Echarts饼图

样式图:

代码:

<template>
  <div class="echartsPie">
     <div id="networkChart" style="width:100%;height:100%;"></div>
  </div>
</template>

<script>
export default {
  name: "echartsPie",
  data() {
    return {};
  },
  mounted() {
    this.drawChart();
  },
  methods: {
    async drawChart() {
      // 基于准备好的dom,初始化echarts实例
      const myPieChart = this.$echarts.init(
        document.getElementById("networkChart")
      );
      // 自定义颜色
      const color = ['#ffe000','#006ced','#00ffff','#00cfff','#ffa800','#ff5b00','#ff3000'];
      const color2 = ['#ffe00079','#006ced79','#00ffff79','#00cfff79','#ffa80079','#ff5b0079','#ff300079'];
      // 图表数据
      const chartData = [{
          name: '农用地',
          value: 1000.25
      },{
          name: '建设用地',
          value: 98.37
      },{
          name: '建设用地',
          value: 300.26
      }];
      const data = [];
      chartData.forEach((item, index) => {
        data.push(
          {
            value: item.value,
            name: item.name,
            itemStyle: {
              normal: {
                borderWidth: 1.5,
                shadowBlur: 20,
                borderColor: color[index],
                shadowColor: color[index], // 图表shadow颜色
                color: color2[index], // 图表填充颜色
              }
            }
          }
        )
      })
      // 指定图表的配置项和数据
      const option = {
        tooltip: {
          trigger: 'item',
          formatter: "{b} : {c} ({d}%)"
        },
        polar: {},
        angleAxis: {
          interval: 1,
          type: 'category',
          data: [],
          z: 10,
          axisLine: {
            show: false,
            lineStyle: {
              color: "#0B4A6B",
              width: 1,
              type: "solid"
            },
          },
          axisLabel: {
            interval: 0,
            show: true,
            color: "#0B4A6B",
            margin: 8,
            fontSize: 16
          },
        },
        radiusAxis: {
          min: 40,
          max: 120,
          interval: 20,
          axisLine: {
            show: false,
            lineStyle: {
              color: "#0B3E5E",
              width: 1,
              type: "solid"
            },
          },
          axisLabel: {
            formatter: '{value} %',
            show: false,
            padding: [0, 0, 20, 0],
            color: "#0B3E5E",
            fontSize: 16
          },
          splitLine: {
            lineStyle: {
              color: "#0B3E5E",
              width: 2,
              type: "solid"
            }
          }
        },
        calculable: true,
        series: [
          {
            // stack: 'a',
            type: 'pie',
            radius: ['20%', '80%'],
            roseType: 'area',
            zlevel:10,
            label: {
              normal: { // 线指向文字展示
                show: true,
                formatter: function(params) {
                    return "{line|}{space|}{n|" +  params.name + "}\n{hr|}\n{d|" + params.data.value + "}"
                },
                rich: {
                  line: {
                    backgroundColor: '#01e798',
                    borderRadius: 1,
                    width: 2,
                    height: 10,
                  },
                  space: {
                    width: 5,
                  },
                  n: {
                    color: '#ffffff',
                    fontSize: 16,
                    fontFamily: "pmzd_title",
                    height: 20
                  },
                  hr: {
                    borderColor: "#ffffff50",
                    width: "100%",
                    borderWidth: 1,
                    height: 0
                  },
                  d: {
                    color: '#bcc8cc',
                    fontSize: 15,
                    fontFamily: "DINPro-Regular",
                    // lineHeight: 10,
                    padding: 4
                  },
                },
                textStyle: {
                  fontSize: 12,
                },
                position: 'outside'
              },
              emphasis: {
                show: true
              }
            },
            labelLine: {
              normal: {
                show: true,
                // lineStyle: {
                //   color: "#fff",
                //   type: "dashed"
                // }
                // length: 20, // 第一段线长
                // length2: 45 // 第二段线长
              },
              emphasis: {
                show: false
              }
            },
            data: data
          }, 
        ]
      };
      // 使用刚指定的配置项和数据显示图表。
      myPieChart.setOption(option);
      window.onresize = myPieChart.resize;
    }
  },
};
</script>
<style lang="scss">
.echartsPie {
  width: 800px;
  height: 600px;
}
</style>

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值