piechart

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

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import { debounce } from '@/utils'

export default {
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.initChart()
    this.__resizeHandler = debounce(() => {
      if (this.chart) {
        this.chart.resize()
      }
    }, 100)
    window.addEventListener('resize', this.__resizeHandler)
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    window.removeEventListener('resize', this.__resizeHandler)
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        title: {
          text: '部门物耗费用统计',
          textStyle: {
            color: '#333',
            fontStyle: 'normal', // 'italic'  'oblique'
            fontSize: 18,
            },
          },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          left: 'center',
          bottom: '10',
          data: ['土木一组', '电气一组', '第三方维修组', '资产处维修组', '材料一组']
        },
        calculable: true,
        series: [
          {
            name: '部门物耗费用统计',
            type: 'pie',
            // 展示成南丁格尔图
            roseType: 'radius',
            //饼图的半径,数组的第一项是内半径,第二项是外半径
            radius: [15, 95],
            //饼图的中心(圆心)坐标,数组的第一项是横坐标,第二项是纵坐标。
            center: ['50%', '50%'],
            // //系列中的数据内容数组
            data: [
              { value: 45, name: '土木一组' },
              { value: 40, name: '电气一组' },
              { value: 90, name: '第三方维修组' },
              { value: 15, name: '资产处维修组' },
              { value: 25, name: '材料一组' }
            ],
            // //初始动画的缓动效果
            animationEasing: 'cubicInOut',
            //初始动画的时长
            animationDuration: 2600
          }
        ]
      })
    }
  }
}
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值