Echarts实现液态填充图

1.引入echarts

import * as echarts from 'echarts';
import 'echarts-liquidfill';

2.创建画布

<div id="liucharts" style="width: 100%;height: 300px"></div>

3.代码实现

initLiuCharts(){
      // 红色水球
      const myCharts = echarts.init(document.getElementById('liucharts'))
      myCharts.setOption({
        series: [{
          backgroundColor: 'transparent',
          type: 'liquidFill',
          radius: '80%',
          data: [0.6,0.6],
          backgroundStyle: {
            color: {
              type: 'radial',
              x: 0.5,
              y: 0.5,
              r: 0.5,
              colorStops: [{
                offset: 0.8,
                color: 'rgba(255, 81, 81, 0.0)'
              },
                {
                  offset: 0.9,
                  color: 'rgba(255, 81, 81, 0.25)'
                },
                {
                  offset: 0.95,
                  color: 'rgba(255, 81, 81, 0.75)'
                },
                {
                  offset: 1,
                  color: 'rgba(255, 81, 81, 1)'
                }],
              globalCoord: false
            },
          },
          itemStyle: {
            shadowBlur: 0,
            color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
              offset: 1,
              color: 'rgba(255, 81, 81, 1)'
            }, {
              offset: 0,
              color: 'rgba(130, 4, 72, 1)'
            }]),
            opacity: 0.7,
          },
          outline: {
            show: false
          },
        }]
      })

      // 黄色水球
      const myCharts = echarts.init(document.getElementById('liucharts'))
      myCharts.setOption({
        backgroundColor: 'transparent',
        series: [{
          type: 'liquidFill',
          radius: '80%',
          center: ['50%', '57.5px'],
          data: [procent, procent],
          backgroundStyle: {
            color: {
              type: 'radial',
              x: 0.5,
              y: 0.5,
              r: 0.5,
              colorStops: [{
                offset: 0.8,
                color: 'rgba(255, 215, 137, 0.0)'
              },
              {
                offset: 0.9,
                color: 'rgba(255, 215, 137, 0.25)'
              },
              {
                offset: 0.95,
                color: 'rgba(255, 215, 137, 0.75)'
              },
              {
                offset: 1,
                color: 'rgba(255, 215, 137, 1)'
              }],
              globalCoord: false
            },
          },
          itemStyle: {
            shadowBlur: 0,
            color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
              offset: 1,
              color: 'rgba(255, 215, 137, 1)'
            }, {
              offset: 0,
              color: 'rgba(161, 57, 25, 1)'
            }]),
            opacity: 0.7,
          },
          outline: {
            show: false
          },
          label: {
            normal: {
              formatter: '',
            },
          },
        }]
      })
        
     //绿色水球
     const myCharts = echarts.init(document.getElementById('liucharts'))
      myCharts.setOption({
        backgroundColor: 'transparent',
        series: [{
          type: 'liquidFill',
          radius: '80%',
          center: ['50%', '57px'],
          data: [procent, procent],
          backgroundStyle: {
            color: {
              type: 'radial',
              x: 0.5,
              y: 0.5,
              r: 0.5,
              colorStops: [{
                offset: 0.8,
                color: 'rgba(24, 221, 138, 0.0)'
              },
              {
                offset: 0.9,
                color: 'rgba(24, 221, 138, 0.25)'
              },
              {
                offset: 0.95,
                color: 'rgba(24, 221, 138, 0.75)'
              },
              {
                offset: 1,
                color: 'rgba(24, 221, 138, 1)'
              }],
              globalCoord: false
            },
          },
          itemStyle: {
            shadowBlur: 0,
            color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
              offset: 1,
              color: 'rgba(24, 221, 138, 1)'
            }, {
              offset: 0,
              color: 'rgba(8, 90, 55, 1)'
            }]),
            opacity: 0.7,
          },
          outline: {
            show: false
          },
          label: {
            normal: {
              formatter: '',
            },
          },
        }]
      })

    }

效果演示,只展示红色

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
可以使用CSS的transform和animation属性来实现液态流动的动画效果。 首先,需要将片包含在一个div中,并设置该div的position属性为relative,以便在之后设置子元素的绝对定位。 然后,使用伪元素:after和:before来创建两个圆形的元素,它们将作为液体的形状。 接下来,使用transform属性来设置这些元素的大小和位置,以形成一个液体的形状。 最后,使用animation属性来设置动画效果,例如改变元素的大小和位置,使其看起来像是液体在流动。 下面是一个简单的示例代码: HTML代码: ``` <div class="liquid"> <img src="your_image_url" alt="your_image_alt"> </div> ``` CSS代码: ``` .liquid { position: relative; overflow: hidden; } .liquid::before, .liquid::after { content: ""; position: absolute; top: 0; left: 0; border-radius: 50%; background-color: #fff; transform: scale(0.5); } .liquid::before { width: 30px; height: 30px; transform: translate(-10px, -10px) scale(0.5); } .liquid::after { width: 40px; height: 40px; transform: translate(20px, 20px) scale(0.5); } .liquid:hover::before, .liquid:hover::after { animation: liquid 1s ease-in-out infinite alternate; } @keyframes liquid { 0% { transform: translate(-10px, -10px) scale(0.5); } 50% { transform: translate(20px, 20px) scale(1); } 100% { transform: translate(50px, 50px) scale(0.5); } } ``` 在这个示例中,当鼠标悬停在液体div上时,液体元素将开始动画。你可以根据自己的需求来调整元素的大小、位置和动画效果,以达到你想要的液态流动的效果。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值