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

vue2+echarts实现水球+外层动效

实现效果

在这里插入图片描述

安装echarts-liquidfill

  • 需要安装echarts-liquidfill!!!
  • 需要安装echarts-liquidfill!!!
  • 需要安装echarts-liquidfill!!!
安装命令
npm install echarts-liquidfill
版本如图:

在这里插入图片描述

实现代码

  data() {
    return {
      chart: null,
      timer: null,
      angle: 0, //角度,用来做简单的动画效果的
      list: [],
      /* this.list = [
          rate,
          {
            value: rate,
            direction: "left", //波浪方向
          },
        ]; */
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    clearInterval(this.timer); // 销毁前,清除时间定时器
    this.timer = null;
  },
  methods: {
    initChart() {
      this.chart = this.$echarts.init(this.$refs.chart3Ref);
      let that = this;
      let option = {
        series: [
          {
            name: "内线",
            type: "custom",
            coordinateSystem: "none",
            renderItem: function (params, api) {
              return {
                type: "arc",
                shape: {
                  cx: api.getWidth() / 2,
                  cy: api.getHeight() / 2,
                  r: Math.min(api.getWidth(), api.getHeight()) / 2.3,
                  startAngle: ((0 + that.angle) * Math.PI) / 180,
                  endAngle: ((90 + that.angle) * Math.PI) / 180,
                },
                style: {
                  stroke: "#0ff",
                  fill: "transparent",
                  lineWidth: that.fontSize(0.03),
                },
                silent: true,
              };
            },
            data: [0],
          },
          {
            name: "内线",
            type: "custom",
            coordinateSystem: "none",
            renderItem: function (params, api) {
              return {
                type: "arc",
                shape: {
                  cx: api.getWidth() / 2,
                  cy: api.getHeight() / 2,
                  r: Math.min(api.getWidth(), api.getHeight()) / 2.3,
                  startAngle: ((180 + that.angle) * Math.PI) / 180,
                  endAngle: ((270 + that.angle) * Math.PI) / 180,
                },
                style: {
                  stroke: "#0ff",
                  fill: "transparent",
                  lineWidth: that.fontSize(0.03),
                },
                silent: true,
              };
            },
            data: [0],
          },
          {
            name: "外线",
            type: "custom",
            coordinateSystem: "none",
            renderItem: function (params, api) {
              return {
                type: "arc",
                shape: {
                  cx: api.getWidth() / 2,
                  cy: api.getHeight() / 2,
                  r: Math.min(api.getWidth(), api.getHeight()) / 2.1,
                  startAngle: ((270 + -that.angle) * Math.PI) / 180,
                  endAngle: ((40 + -that.angle) * Math.PI) / 180,
                },
                style: {
                  stroke: "#0ff",
                  fill: "transparent",
                  lineWidth: that.fontSize(0.03),
                },
                silent: true,
              };
            },
            data: [0],
          },
          {
            name: "外线",
            type: "custom",
            coordinateSystem: "none",
            renderItem: function (params, api) {
              return {
                type: "arc",
                shape: {
                  cx: api.getWidth() / 2,
                  cy: api.getHeight() / 2,
                  r: Math.min(api.getWidth(), api.getHeight()) / 2.1,
                  startAngle: ((90 + -that.angle) * Math.PI) / 180,
                  endAngle: ((220 + -that.angle) * Math.PI) / 180,
                },
                style: {
                  stroke: "#0ff",
                  fill: "transparent",
                  lineWidth: that.fontSize(0.03),
                },
                silent: true,
              };
            },
            data: [0],
          },
          {
            name: "线头点",
            type: "custom",
            coordinateSystem: "none",
            renderItem: function (params, api) {
              let x0 = api.getWidth() / 2;
              let y0 = api.getHeight() / 2;
              let r = Math.min(api.getWidth(), api.getHeight()) / 2.1;
              let point = that.getCirlPoint(x0, y0, r, 90 + -that.angle);
              return {
                type: "circle",
                shape: {
                  cx: point.x,
                  cy: point.y,
                  r: 5,
                },
                style: {
                  stroke: "#0ff", //绿
                  fill: "#0ff",
                },
                silent: true,
              };
            },
            data: [0],
          },
          {
            name: "线头点",
            type: "custom",
            coordinateSystem: "none",
            renderItem: function (params, api) {
              let x0 = api.getWidth() / 2;
              let y0 = api.getHeight() / 2;
              let r = Math.min(api.getWidth(), api.getHeight()) / 2.1;
              let point = that.getCirlPoint(x0, y0, r, 270 + -that.angle);
              return {
                type: "circle",
                shape: {
                  cx: point.x,
                  cy: point.y,
                  r: 5,
                },
                style: {
                  stroke: "#0ff", //绿
                  fill: "#0ff",
                },
                silent: true,
              };
            },
            data: [0],
          },
          {
            // value: 50, //  内容 配合formatter
            type: "liquidFill",
            radius: "70%", // 控制中间圆球的尺寸(此处可以理解为距离外圈圆的距离控制)
            center: ["50%", "50%"],
            data: this.list, // data个数代表波浪数
            backgroundStyle: {
              borderWidth: this.fontSize(0.01),
              color: "rgba(62, 208, 255, 1)", // 球体本景色
            },
            amplitude: "6  %", //波浪的振幅
            // 修改波浪颜色
            color: [
              {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 1,
                    color: "#6CDEFC",
                  },
                  {
                    offset: 0,
                    color: "#429BF7",
                  },
                ],
                globalCoord: false,
              },
            ],
            label: {
              normal: {
                formatter: function (params) {
                  return params.value * 100 + " %";
                },
                textStyle: {
                  fontSize: this.fontSize(0.3),
                  color: "#fff",
                },
              },
            },
            backgroundStyle: {
              borderWidth: that.fontSize(0.01),
              color: "transparent",
            },
            outline: {
              show: true,
              itemStyle: {
                borderColor: "#0ff",
                borderWidth: that.fontSize(0.02),
              },
              borderDistance: that.fontSize(0.03),
            },
          },
          {
            type: "pie",
            z: 1,
            center: ["50%", "50%"],
            radius: ["72%", "75%"], // 控制外圈圆的粗细
            hoverAnimation: false,
            data: [
              {
                name: "",
                value: 0,
                labelLine: {
                  show: false,
                },
                itemStyle: {
                  color: "#00AFFF",
                },
                emphasis: {
                  labelLine: {
                    show: false,
                  },
                },
              },
            ],
          },
        ],
      };
      this.chart.setOption(option);
      this.timer = setInterval(() => {
        this.draw();
      }, 100);
    },
    
    getCirlPoint(x0, y0, r, angle) {
      let x1 = x0 + r * Math.cos((angle * Math.PI) / 180);
      let y1 = y0 + r * Math.sin((angle * Math.PI) / 180);
      return {
        x: x1,
        y: y1,
      };
    },

    draw() {
      this.angle = this.angle + 3;
      let option = this.chart.getOption();
      // console.log(option, "option");
      option.series[6].data = this.list;
      this.chart.setOption(option);
    },
  },

http://www.kler.cn/a/464486.html

相关文章:

  • 网络IP协议
  • Windows11安装Oracle11g以及plsqldev工具连接配置
  • git 创建tag, 并推送到远程仓库,启动actions构建release自动发布
  • Excel VBA 自动填充空白并合并相同值的解决方案
  • unity学习5:创建一个自己的3D项目
  • (二)当人工智能是一个函数,函数形式怎么选择?ChatGPT的函数又是什么?
  • 无人机飞手培训机构大量新增,考取飞手证参军入伍还有优势吗?
  • PHP框架+gatewayworker实现在线1对1聊天--gatewayworker说明(2)
  • 怎么免费查询企业的行政监管信息?
  • 入门嵌入式(二)——中断
  • 设计模式 结构型 适配器模式(Adapter Pattern)与 常见技术框架应用 解析
  • CPO-SVMD分解 | Matlab实现CPO-SVMD豪猪算法优化逐次变分模态分解
  • 图像概念与分类
  • Linux下Shell编程之ps命令详解及示例
  • std optional 的使用
  • Redis--高可用(主从复制、哨兵模式、分片集群)
  • commit 错分支的一些补救操作
  • uni-app 多平台分享实现指南
  • 【Unity3D】ECS入门学习(十)NativeContainer、EntityCommandBuffer、CompleteDependency
  • el-table树形懒加载展开改为点击行展开
  • SAP财务凭证的更改、冲销的方式
  • python: generate model and DAL using Oracle
  • 【从零开始入门unity游戏开发之——C#篇43】C#补充知识——值类型和引用类型汇总补充、变量的生命周期与性能优化、值类型和引用类型组合使用
  • 虚拟路由冗余协议VRRP(Virtual Router Redundancy Protocol)
  • Springboot使用RabbitMQ实现关闭超时订单的一个简单示例
  • 【面试】深入理解 JavaScript 中的 Object.freeze()