当前位置: 首页 > news >正文

vue-饼形图-详细

显示效果

代码

<template>

  <div style="height: 350px;">

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

  </div>

</template>

<script>

import * as echarts from 'echarts';

require('echarts/theme/macarons') // echarts theme

import resize from './mixins/resize'

export default {

  mixins: [resize],

  props: {

    className: {

      type: String,

      default: 'chart'

    },

    width: {

      type: String,

      default: '100%'

    },

    height: {

      type: String,

      default: '300px'

    }

  },

  data() {

    return {

      chart: null,

      pieChartData:[

          { value: 320, name: '找工作' },

          { value: 240, name: '广告推广' },

          { value: 149, name: '二手物品' },

          { value: 100, name: '二手车' },

          { value: 59, name: '拼车出行' },

          { value: 59, name: '宠物出售' },

          { value: 59, name: '房屋出售' },

          { value: 59, name: '上门出售' }

      ]

    }

  },

  mounted() {

    this.$nextTick(() => {

      this.initChart()

    })

  },

  beforeDestroy() {

    if (!this.chart) {

      return

    }

    this.chart.dispose()

    this.chart = null

  },

  methods: {

    initChart() {

      // 计算百分比

      let mdataList = this.pieChartData

      let total = 0

      const target = new Map();              

      mdataList.forEach((item) => {

          // 计算value的和,用来算百分比

          total += item.value

          // 组成 map {A:1212} ,用来下面获取 value

          target.set(item.name, item.value)

      })

      this.chart = echarts.init(this.$el, 'macarons');

      this.chart.setOption({

        tooltip: {

          trigger: 'item',

          formatter: '{a} <br/>{b} : {c} ({d}%)'

        },

        legend: {

          left: 'right',

          orient: 'vertical', // 布局方式,默认为水平布局,可选为:'horizontal' ¦ 'vertical'

          top: '50',

          data: ['找工作', '广告推广', '二手物品', '二手车', '拼车出行','宠物出售','房屋出售','上门出售'],

          formatter: function(name) {

            let lists = [];

            let inum = target.get(name) / total * 100;

            //保留inum小数点后2位

            let vnum = parseFloat(inum).toFixed(2);

            lists.push(name + '-' + vnum + '%');

            return lists;

          },

        },

        title: {

          text: '分类统计',

          left: 'left',

        },

        series: [

          {

            name: '分类统计',

            type: 'pie',

            roseType: 'radius',

            radius: [15, 95],

            center: ['35%', '50%'],

            data: this.pieChartData,

            animationEasing: 'cubicInOut',

            animationDuration: 2600

          }

        ]

      })

    }

  }

}

</script>

http://www.lryc.cn/news/376802.html

相关文章:

  • MySQL-备份+日志:介质故障与数据库恢复
  • 嵌入式开发十八:USART串口通信实验
  • redis复习
  • SUSE linux的快照和恢复
  • 【Qt快速入门(六)】- QLineEdit按钮的使用
  • 常用损失函数详解:广泛使用的优化约束方法
  • 鸿蒙开发组件:【创建DataAbility】
  • 配电室数据中心巡检3d可视化搭建的详细步骤
  • TIME_WAIT的危害
  • 搜维尔科技邀您共赴2024第四届轨道车辆工业设计国际研讨会
  • 智能中人类造成的风险、机器造成的风险、环境造成的风险
  • MYSQL基础查询
  • 【Golang】Go 中的生产者-消费者模式
  • 【通过新能源汽车的智慧数字底盘技术看计算机的相关技术堆栈?以后是软硬结合的全能程序员的天下,取代全栈(前后端都会的全栈程序员)】
  • Python网络爬虫4-实战爬取pdf
  • 超神级!Markdown最详细教程,程序员的福音
  • Android OTA 升级基础知识详解+源码分析
  • 【吊打面试官系列-Mysql面试题】SQL 语言包括哪几部分?每部分都有哪些操作关键字?
  • Redis的缓存击穿与解决
  • 网络层 IP协议【计算机网络】【协议格式 || 分片 || 网段划分 || 子网掩码】
  • Python学习笔记14:进阶篇(三)。类的终结篇,类的导入和模块的导入。
  • C++ lambda表达式举例
  • 持续总结中!2024年面试必问 20 道设计模式面试题(五)
  • 嵌入式面经111题答案汇总(含技术答疑)_嵌入式项目源码分享
  • 鸿蒙开发通信与连接:【@ohos.connectedTag (有源标签)】
  • 在线编程工具
  • NSSCTF中的[WUSTCTF 2020]朴实无华、[FSCTF 2023]源码!启动! 、[LitCTF 2023]Flag点击就送! 以及相关知识点
  • Vue49-props属性
  • CVE-2020-1957 漏洞复现
  • 网工内推 | 中国电信、香港宽频系统工程师,CCIE认证优先,最高年薪25w