pieChart

npm i echarts ---save-dev
main.js
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
chart
<template>
<div class="chart">
</div>
</template>
<script>
export default {
  data() {
    return {
      color: ["#4DB628", "#1CDE8E", "#3CE7F2", "#2E81FF", "#8B3BF8", "#D03B7A", "#FF8523", "#F4C60D"],
      data:[{
          value: 335,
          name: '别墅类房地产'
        },
        {
          value: 310,
          name: '具有别墅风格的经营性项目'
        },
        {
          value: 234,
          name: '私家庄园'
        },
        {
          value: 135,
          name: '私人别墅'
        }
      ],
      total: 0,
      myChart: {}
    }
  },
  mounted() {
    let _this = this;
    _this.init()
    setTimeout(() => {
      _this.myChart.resize()
    }, 1000)
    window.addEventListener("resize", function() {
      _this.myChart.resize()
    })
  },
  methods: {
    init() {
      this.data = this.pieData
      for (var i = 0; i < this.data.length; i++) {
        this.total += this.data[i].value
      }
      this.drawLine();
    },
    drawLine() {
      this.myChart = this.$echarts.init(this.$el)
      let self = this
      this.myChart.clear()
      // 绘制图表
      this.myChart.setOption({
        backgroundColor: "#fff",
        title: {
          text: '总数',
          subtext: self.total,
          textStyle: {
            color: '#333',
            fontSize: 14,
            align: 'center'
          },
          subtextStyle: {
            fontSize: 24,
            color: '#333',
            fontWeight: 'bold',
          },
          x: 'center',
          y: '44%',
        },
        tooltip: {
          trigger: 'item',
          formatter: "{b} : {c}"
        },
        legend: {
          show: false
        },
        color: self.color,
        series: [{
            name: '访问来源',
            type: 'pie',
            radius: ['35%', '45%'],
            center: ['50%', '50%'],
            data: self.data,
            label: {
              normal: {
                show: true,
                formatter: "{b} \n {num|{c}}",
                fontSize: 14,
                rich: {
                  num: {
                    lineHeight: 24,
                    fontSize: 14,
                    align: 'center'
                  }
                }
              },
              emphasis: {
                show: true
              }
            },
            itemStyle: {
              emphasis: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              },
              normal: {
                borderColor: 'rgba(255, 255, 255, 1)',
                borderWidth: 0,
              },
            }
          },
          {
            name: '外边框',
            type: 'pie',
            hoverAnimation: false, //鼠标移入变大
            center: ['50%', '50%'],
            radius: ['47%', '47.6%'],
            label: {
              normal: {
                show: false
              }
            },
            data: self.data,
          },
        ]
      });
    }
  },
}
</script>
<style lang="scss" scoped>

</style>

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值