Echarts图——饼图动态

news/2024/7/10 2:58:07 标签: vue, echarts, 饼图, 动态

Echarts图——饼图动态


代码

vue"><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>

效果展示

在这里插入图片描述


http://www.niftyadmin.cn/n/482803.html

相关文章

iOS开发 - 不小心删除了Copy Bundle Resources怎么办?(多人开发频繁添加删除图片导致图片路径重复,编译报错)

Copy Bundle Resources在iOS中至关重要&#xff0c;如果一不小心删除了这一项&#xff0c;整个工程就废了&#xff0c;无法运行。Copy Bundle Resources存在于Build Phases中&#xff0c;一般来说很少会有人注意到它&#xff0c;即使不小心删除了也很难发现少了什么&#xff0c…

iOS开发 - 打包静态framework后,引用时必须做的一件事,否则崩溃

默认添加framework后运行项目会直接崩溃&#xff0c;报错如下&#xff1a; dyld: Library not loaded: rpath/AppKit.framework/AppKitReferenced from: /var/containers/Bundle/Application/2E6B9570-C294-4C73-9C6A-0D1C06DC534D/test.app/testReason: image not found (lld…

echarts-折线图,动态

echarts-折线图&#xff0c;动态 代码 <template><div style"width: 100%; height: 100%" id"chartsR"></div> </template><script> import echarts from "echarts"; export default {mounted() {this.drawLine(…

echarts-柱状,动态

echarts-柱状&#xff0c;动态 代码 <template><div style"width:100%;height:100%;" id"issues"></div> </template><script>import echarts from echartsexport default {mounted() {this.drawLine()},methods: { drawLi…

vue中鼠标右击菜单(rightmenu),以及回调处理

vue中鼠标右击菜单&#xff08;rightmenu&#xff09;&#xff0c;以及回调处理 安装和引用 npm install rightmenu --save-devimport rightMenu from "rightmenu"Vue.use(rightMenu) 使用案例 <template><div><h3>24324</h3><button …

vue动态时间显示

vue动态时间显示 1. 封装date.js function showDate() {const date new Date();const yeardate.getFullYear();const monthdate.getMonth()1;const daydate.getDate();const hourdate.getHours();const mindate.getMinutes();const secdate.getSeconds();document.getElemen…

vue+NodeJS项目部署打包上线到阿里云完整版(前台vue,后台node)

vueNodeJS项目部署打包上线到阿里云完整版&#xff08;前台vue&#xff0c;后台node&#xff09; 阿里云服务器配置 购买云服务器&#xff0c;这里不做介绍。 改root密码&#xff1a; sudo passwd root 安装宝塔&#xff0c;执行一下命令 Centos&#xff1a;yum install -y …

校验电话号码自动生成标签(包含多个粘体复制生成标签)

校验电话号码自动生成标签 <template><div><!-- <label class"labelname">{{labelname}}</label> --><div class"inputbox"><div class"arrbox"><div v-for"(item, index) in labelarr"…