vue echarts之饼图

上一篇搞了个仪表盘,这一篇搞个饼图

无图言d,所以,展示:
在这里插入图片描述

直接上代码:

<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
export default {
  name: 'TestChart',
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '200px'
    },
    autoResize: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      chart: null
    }
  },
  created () {
    this.$nextTick(()=> {
      this.initChart()
    })
  },
  methods: {
    initChart() {
      let eVal = 40
      this.chart = echarts.init(this.$el, 'macarons') // 引用echarts自定义主题
      this.chart.setOption({
        title: {
          text: 'xx使用率',
          textStyle: {
            fontSize: 16,
            top: '10%',
            left: '20%'
          }
        },
        tooltip: {
          trigger: "item",
          formatter: "{d}%",
          show: false
        },
        legend: {
          orient: 'vertical',
          x: 'left',
          show: false
        },
        series: [
          {
            name: '',
            type: 'pie',
            radius: ["45%", "50%"],  // 饼图半径,内半径和外半径
            //center: ["30%", "70%"],  // 调整饼图位置
            avoidLabelOverlap: true,   //启用防止标签重叠
            hoverAnimation: false,    //开启放大动画
            label: {  // 饼图图形上的文本标签
              normal: { // normal是图形在默认状态下的样式
                show: false,  // 不显示label
                position: "center",   //文字居中显示
                formatter: "{d}% \r\n {b}"  //显示文本内容,d代表百分比,b代表name文本
              },
              // emphasis: {
              //   show: true,
              // },
            },
            labelLine: {
              normal: {
                show: false,
              },
            },
            data: [
              {
                value: eVal,
                name: "利用率",
                label: {
                  show: true,
                },
                itemStyle: {
                  color: "#DC143C",
                }
              },
              {
                value: 100 - eVal,
                name: "",
                itemStyle: {
                  color: "#D3D3D3",
                },
              },
            ],
          }
        ]
      })
    }
  },
}
</script>

<style scoped>

</style>

后续有时间再更新。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值