Echarts图——饼图动态


Echarts图——饼图动态


代码

<template>
  <div style="width: 100%; height: 100%" id="chartsL"></div>
</template>

<script>
import echarts from "echarts";
export default {
  mounted() {
    this.drawLine();
  },
  methods: {
    drawLine() {
      let img = require("@/assets/img/zjx/analysisTypesChart.png");
      let myChart = echarts.init(document.getElementById("chartsL"));
      var trafficWay = [
        {
          name: "视频",
          value: 200,
          fontSize: 10,
        },
        {
          name: "图片",
          value: 100,
          fontSize: 10,
        },
        {
          name: "文字",
          value: 300,
          fontSize: 10,
        },
        {
          name: "音频",
          value: 400,
          fontSize: 10,
        },
      ];

      var dataTs = ["视频", "图片", "文字", "音频"];

      var data = [];
      var color = [
        "#00ffff",
        "#00cfff",
        "#006ced",
        "#ffe000",
        "#ffa800",
        "#ff5b00",
        "#ff3000",
      ];
      for (var i = 0; i < trafficWay.length; i++) {
        data.push(
          {
            value: trafficWay[i].value,
            name: trafficWay[i].name,
            itemStyle: {
              normal: {
                borderWidth: 5,
                shadowBlur: 5, //圆环阴影
                borderColor: color[i],
                shadowColor: color[i],
              },
            },
          },
          {
            value: 20, //间隙
            name: "",
            itemStyle: {
              normal: {
                label: {
                  show: false,
                },
                labelLine: {
                  show: false,
                },
                color: "rgba(0, 0, 0, 0)",
                borderColor: "rgba(0, 0, 0, 0)",
                borderWidth: 0,
              },
            },
          }
        );
      }
      var seriesOption = [
        {
          name: "",
          type: "pie",
          clockWise: false,
          radius: [50, 52],
          hoverAnimation: true,
          itemStyle: {
            normal: {
              label: {
                // normal:{},
                show: true,
                position: "outside",
                // color: '#fff',//指示字体颜色

                formatter: ["{b|{b}}", "{c|{c}} {f|条}{d|{d}}{e|%}"].join("\n\n"),
                // formatter: ['{a|{a}}', '{c|{c}}'].join('\n'),
                rich: {
                  b: {
                    color: "#fff",
                    fontSize: 10,
                  },
                  c: {
                    fontSize: 10,
                  },
                  d: {
                    fontSize: 10,
                  },
                  e: {
                    // color: '#fff',
                    fontSize: 8,
                  },
                  f: {
                    fontSize: 10,
                  },
                },

                padding: [-40, -60], //牵引线调整字体距离
              },
              labelLine: {
                length: 20, //角度长度
                length2: 50, //水平长度
                show: true,
                color: "#00ffff",
              },
            },
          },
          data: data,
        },
      ];
      var option = {
        color: color,

        title: {
          text: "素材总条目",
          subtext: "6514684",
          left: "center",
          top: "40%",
          // top: "center",
          textStyle: {
            fontSize: 10,
            color: "#fff",
          },
          subtextStyle: {
            fontSize: 11,
            color: "#fff",
          },
        },

        graphic: {
          elements: [
            //内圆环样式
            {
              type: "image",
              z: 3,
              style: {
                image: img,
                width: 78,
                height: 78,
              },
              left: "center",
              top: "center",
              position: [100, 100],
            },
          ],
        },
        tooltip: {
          show: false,
        },
        legend: {
          //标尺那一块样式
          icon: "roundRect",
          orient: "vertical",
          itemWidth: 13,
          itemHeight: 10,
          // x: 'left',
          data: dataTs,
          left: 200, //调整标尺的位置
          bottom: 20,
          align: "left",
          textStyle: {
            color: "#fff",
            fontSize: 8,
          },
          style: {
            width: 10,
            height: 10,
          },
          itemGap: 4, //标识字体行间距
        },
        toolbox: {
          show: false,
        },
        series: seriesOption,
      }

      //使用制定的配置项和数据显示图表
      myChart.setOption(option);
      function createExample(option, tooltipOption) {
        // 基于准备好的dom,初始化echarts图表
        // 为echarts对象加载数据
        myChart.setOption(option);
        tools.loopShowTooltip(myChart, option, tooltipOption); //第一个参数需要改一下
      }
      createExample(option, {
        loopSeries: true,
        // 间隔时间
         interval: 2000,
      });
    },
  },
};
</script>

效果展示

在这里插入图片描述

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

拼搏的小浣熊

你的鼓励是我创作的巨大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值